Skip to content

Commit

Permalink
Wrap more methods that may fail depending on job store
Browse files Browse the repository at this point in the history
  • Loading branch information
mausch committed May 24, 2013
1 parent 4a156ff commit 53b9fed
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 47 deletions.
61 changes: 32 additions & 29 deletions QuartzNetWebConsole.Views/Views.vb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Public Module Views
</html>
End Function

Public Function TriggerGroup(group As String, paused As Boolean, thisUrl As String, highlight As String, triggers As IEnumerable(Of TriggerWithState)) As XElement
Public Function TriggerGroup(group As String, paused As Boolean?, thisUrl As String, highlight As String, triggers As IEnumerable(Of TriggerWithState)) As XElement
Dim schedulerOp = Function(method As String) "scheduler.ashx?method=" + method +
"&groupName=" + group +
"&next=" + HttpUtility.UrlEncode(thisUrl)
Expand All @@ -244,10 +244,11 @@ Public Module Views
<body>
<a href="index.ashx">Index</a>
<h1>Trigger group <%= group %></h1>
Status: <%= If(paused, "paused", "started") %>
<%= If(paused,
SimpleForm(schedulerOp("ResumeTriggerGroup"), "Resume this trigger group"),
SimpleForm(schedulerOp("PauseTriggerGroup"), "Pause this trigger group")) %>
Status: <%= IfNullable(paused, ifNull:="N/A", ifTrue:="paused", ifFalse:="started") %>
<%= IfNullable(paused,
ifNull:=<span></span>,
ifTrue:=SimpleForm(schedulerOp("ResumeTriggerGroup"), "Resume this trigger group"),
ifFalse:=SimpleForm(schedulerOp("PauseTriggerGroup"), "Pause this trigger group")) %>
<br style="clear:both"/>
<h2>Triggers</h2>
<%= TriggerTable(triggers, thisUrl, highlight) %>
Expand Down Expand Up @@ -336,34 +337,36 @@ Public Module Views

Public Function TriggerTable(triggers As IEnumerable(Of TriggerWithState), thisUrl As String, highlight As String) As XElement
Return _
<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>Priority</th>
<th>Job group</th>
<th>Job name</th>
<th>Start time UTC</th>
<th>End time UTC</th>
<th>Final fire time UTC</th>
<th>Next fire time UTC</th>
<th>Repeat count</th>
<th>Repeat interval</th>
<th>Times triggered</th>
<th>Cron</th>
<th>Calendar</th>
<th>State</th>
<th></th>
</tr>
<%= From tr In triggers
If(triggers Is Nothing,
<span>Not available</span>,
<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>Priority</th>
<th>Job group</th>
<th>Job name</th>
<th>Start time UTC</th>
<th>End time UTC</th>
<th>Final fire time UTC</th>
<th>Next fire time UTC</th>
<th>Repeat count</th>
<th>Repeat interval</th>
<th>Times triggered</th>
<th>Cron</th>
<th>Calendar</th>
<th>State</th>
<th></th>
</tr>
<%= From tr In triggers
Let trigger = tr.Trigger
Let high = highlight = trigger.Key.ToString()
Let simpleTrigger = TryCast(trigger, SimpleTriggerImpl)
Let cronTrigger = TryCast(trigger, CronTriggerImpl)
Let op = Function(method As String) "scheduler.ashx?method=" & method &
"&triggerName=" + trigger.Key.Name +
"&groupName=" + trigger.Key.Group +
"&next=" + HttpUtility.UrlEncode(thisUrl)
"&triggerName=" + trigger.Key.Name +
"&groupName=" + trigger.Key.Group +
"&next=" + HttpUtility.UrlEncode(thisUrl)
Select
<tr id=<%= trigger.Key.ToString() %>
class=<%= If(highlight = trigger.Key.ToString(), "highlight", "") %>>
Expand Down Expand Up @@ -398,6 +401,6 @@ Public Module Views
<%= SimpleForm(op("UnscheduleJob"), "Delete") %>
</td>
</tr> %>
</table>
</table>)
End Function
End Module
4 changes: 2 additions & 2 deletions QuartzNetWebConsole/ControllerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ private static ISchedulerWrapper GetSchedulerWrapper() {
Route("log", LogController.Execute),
Route("scheduler", ctx => SchedulerController.Execute(ctx, GetSchedulerWrapper)),
Route("static", StaticController.Execute),
Route("triggerGroup", ctx => TriggerGroupController.Execute(ctx, Setup.Scheduler)),
Route("triggersByJob", ctx => TriggersByJobController.Execute(ctx, Setup.Scheduler)),
Route("triggerGroup", ctx => TriggerGroupController.Execute(ctx, GetSchedulerWrapper)),
Route("triggersByJob", ctx => TriggersByJobController.Execute(ctx, GetSchedulerWrapper)),
};

public static Route Route(string path, Action<HttpContextBase> action) {
Expand Down
26 changes: 17 additions & 9 deletions QuartzNetWebConsole/Controllers/TriggerGroupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@
using System.Web;
using MiniMVC;
using Quartz;
using Quartz.Impl;
using Quartz.Impl.Matchers;
using QuartzNetWebConsole.Utils;
using QuartzNetWebConsole.Views;
using System.Collections.Generic;

namespace QuartzNetWebConsole.Controllers {
public class TriggerGroupController {
public static void Execute(HttpContextBase context, Func<IScheduler> getScheduler) {
private static IEnumerable<TriggerWithState> GetTriggers(ISchedulerWrapper scheduler, string group) {
var triggerKeys = scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEquals(group));
if (triggerKeys == null)
return null;
return triggerKeys.Select(t => {
var trigger = scheduler.GetTrigger(t);
var state = scheduler.GetTriggerState(t);
return new TriggerWithState(trigger, state);
});
}

public static void Execute(HttpContextBase context, Func<ISchedulerWrapper> getScheduler) {
var scheduler = getScheduler();
var highlight = context.Request.QueryString["highlight"];
var group = context.Request.QueryString["group"];
var triggerKeys = scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEquals(group));
var triggers = triggerKeys
.Select(t => {
var trigger = scheduler.GetTrigger(t);
var state = scheduler.GetTriggerState(t);
return new TriggerWithState(trigger, state);
});
var triggers = GetTriggers(scheduler, group);
var thisUrl = context.Request.RawUrl;
var paused = scheduler.IsTriggerGroupPaused(group);
var highlight = context.Request.QueryString["highlight"];
var v = Views.Views.TriggerGroup(group, paused, thisUrl, highlight, triggers);
context.Response.Html(Helpers.XHTML(v));
}
Expand Down
22 changes: 15 additions & 7 deletions QuartzNetWebConsole/Controllers/TriggersByJobController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,30 @@
using System.Web;
using MiniMVC;
using Quartz;
using QuartzNetWebConsole.Utils;
using QuartzNetWebConsole.Views;
using System.Collections.Generic;

namespace QuartzNetWebConsole.Controllers {
public class TriggersByJobController {
public static void Execute(HttpContextBase context, Func<IScheduler> getScheduler) {
private static IEnumerable<TriggerWithState> GetTriggers(ISchedulerWrapper scheduler, JobKey jobKey) {
var triggers = scheduler.GetTriggersOfJob(jobKey);
if (triggers == null)
return null;
return triggers.Select(t => {
var state = scheduler.GetTriggerState(t.Key);
return new TriggerWithState(t, state);
});
}

public static void Execute(HttpContextBase context, Func<ISchedulerWrapper> getScheduler) {
var scheduler = getScheduler();
var highlight = context.Request.QueryString["highlight"];
var group = context.Request.QueryString["group"];
var job = context.Request.QueryString["job"];
var jobKey = new JobKey(job, group);
var triggers = GetTriggers(scheduler, jobKey);
var thisUrl = context.Request.RawUrl;
var triggers = scheduler.GetTriggersOfJob(jobKey)
.Select(t => {
var state = scheduler.GetTriggerState(t.Key);
return new TriggerWithState(t, state);
});
var highlight = context.Request.QueryString["highlight"];
var m = new TriggersByJobModel(triggers, thisUrl, group, job, highlight);
context.Response.Html(Helpers.XHTML(Views.Views.TriggersByJob(m)));
}
Expand Down
4 changes: 4 additions & 0 deletions QuartzNetWebConsole/Utils/ISchedulerWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ public interface ISchedulerWrapper {
bool InStandbyMode { get; }
ICalendar GetCalendar(string name);
SchedulerMetaData GetMetaData();
IEnumerable<ITrigger> GetTriggersOfJob(JobKey jobKey);
ISet<TriggerKey> GetTriggerKeys(GroupMatcher<TriggerKey> matcher);
ITrigger GetTrigger(TriggerKey triggerKey);
TriggerState GetTriggerState(TriggerKey triggerKey);
}
}
25 changes: 25 additions & 0 deletions QuartzNetWebConsole/Utils/SchedulerWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Quartz;
using Quartz.Collection;
using Quartz.Impl.Matchers;
Expand Down Expand Up @@ -142,6 +143,30 @@ public SchedulerMetaData GetMetaData() {
return scheduler.GetMetaData();
}

public IEnumerable<ITrigger> GetTriggersOfJob(JobKey jobKey) {
try {
return scheduler.GetTriggersOfJob(jobKey);
} catch (NotImplementedException) {
return null;
}
}

public ISet<TriggerKey> GetTriggerKeys(GroupMatcher<TriggerKey> matcher) {
try {
return scheduler.GetTriggerKeys(matcher);
} catch (NotImplementedException) {
return null;
}
}

public ITrigger GetTrigger(TriggerKey triggerKey) {
return scheduler.GetTrigger(triggerKey);
}

public TriggerState GetTriggerState(TriggerKey triggerKey) {
return scheduler.GetTriggerState(triggerKey);
}

public string SchedulerName {
get {
return scheduler.SchedulerName;
Expand Down

0 comments on commit 53b9fed

Please sign in to comment.