Skip to content

Commit

Permalink
Wrap IsJobGroupPaused / IsTriggerGroupPaused, as they're not always s…
Browse files Browse the repository at this point in the history
…upported.
  • Loading branch information
mausch committed Dec 24, 2012
1 parent 722fdd5 commit a43573b
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 23 deletions.
4 changes: 2 additions & 2 deletions QuartzNetWebConsole.Views/GroupWithStatus.vb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Public Class GroupWithStatus
Public ReadOnly Name As String
Public ReadOnly Paused As Boolean
Public ReadOnly Paused As Boolean?

Public Sub New(name As String, paused As Boolean)
Public Sub New(name As String, paused As Boolean?)
Me.Name = name
Me.Paused = paused
End Sub
Expand Down
7 changes: 7 additions & 0 deletions QuartzNetWebConsole.Views/Helpers.vb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ Public Module Helpers
StripeTrs(e)
Return e.MakeHTML5Doc()
End Function

Public Function IfNullable(Of T)(value As Boolean?, ifNull As T, ifTrue As T, ifFalse As T) As T
If Not value.HasValue Then
Return ifNull
End If
Return If(value.Value, ifTrue, ifFalse)
End Function
End Module
33 changes: 18 additions & 15 deletions QuartzNetWebConsole.Views/Views.vb
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,22 @@ Public Module Views
</rss>
End Function

Public Function SchedulerStatus(scheduler As IScheduler, metadata As SchedulerMetaData) As XElement
Public Function SchedulerStatus(schedulerName As String, inStandby As Boolean, metadata As SchedulerMetaData) As XElement
Return _
<div class="group">
<h2>Scheduler name: <%= scheduler.SchedulerName %></h2>
<h2>Scheduler name: <%= schedulerName %></h2>
<div style="float: left">
Job store: <%= metadata.JobStoreType %><br/>
Supports persistence: <%= YesNo(metadata.JobStoreSupportsPersistence) %><br/>
Number of jobs executed: <%= metadata.NumberOfJobsExecuted %><br/>
Running since: <%= metadata.RunningSince %><br/>
Status: <%= If(scheduler.InStandbyMode, "stand-by", "running") %>
Status: <%= If(inStandby, "stand-by", "running") %>
<br/>
<a href="log.ashx">View log</a>
</div>
<div style="float: right">
<%= SimpleForm("scheduler.ashx?method=Shutdown", "Shut down") %>
<%= If(scheduler.InStandbyMode,
<%= If(inStandby,
SimpleForm("scheduler.ashx?method=Start", "Start"),
SimpleForm("scheduler.ashx?method=Standby", "Stand by")) %>
<%= SimpleForm("scheduler.ashx?method=PauseAll", "Pause all triggers") %>
Expand All @@ -100,15 +100,15 @@ Public Module Views

End Function

Public Function SchedulerListeners(scheduler As IScheduler) As XElement
Public Function SchedulerListeners(listeners As IEnumerable(Of ISchedulerListener)) As XElement
Return _
<div class="group">
<h2>Scheduler listeners</h2>
<table>
<tr>
<th>Type</th>
</tr>
<%= From l In scheduler.ListenerManager.GetSchedulerListeners()
<%= From l In listeners
Select
<tr>
<td><%= l.GetType() %></td>
Expand Down Expand Up @@ -157,11 +157,12 @@ Public Module Views
<td>
<a href=<%= entity & "Group.ashx?group=" & group.Name %>><%= group.Name %></a>
</td>
<td><%= If(group.Paused, "Paused", "Started") %></td>
<td><%= IfNullable(group.Paused, ifNull:="N/A", ifTrue:="Paused", ifFalse:="Started") %></td>
<td>
<%= If(group.Paused,
SimpleForm("scheduler.ashx?method=Resume" & entity & "Group&groupName=" + group.Name, "Resume"),
SimpleForm("scheduler.ashx?method=Pause" & entity & "Group&groupName=" + group.Name, "Pause")) %>
<%= IfNullable(group.Paused,
ifNull:=<span></span>,
ifTrue:=SimpleForm("scheduler.ashx?method=Resume" & entity & "Group&groupName=" + group.Name, "Resume"),
ifFalse:=SimpleForm("scheduler.ashx?method=Pause" & entity & "Group&groupName=" + group.Name, "Pause")) %>
</td>
</tr>
%>
Expand Down Expand Up @@ -201,7 +202,9 @@ Public Module Views

Public ReadOnly GlobalTriggerListeners As Func(Of ICollection(Of KeyValuePair(Of String, Type)), XElement) = GlobalEntityListeners("Trigger")

Public Function IndexPage(scheduler As IScheduler,
Public Function IndexPage(schedulerName As String,
inStandby As Boolean,
listeners As IEnumerable(Of ISchedulerListener),
metadata As SchedulerMetaData,
triggerGroups As IEnumerable(Of GroupWithStatus),
jobGroups As IEnumerable(Of GroupWithStatus),
Expand All @@ -215,8 +218,8 @@ Public Module Views
<%= Stylesheet %>
</head>
<body>
<%= SchedulerStatus(scheduler, metadata) %>
<%= SchedulerListeners(scheduler) %>
<%= SchedulerStatus(schedulerName, inStandby, metadata) %>
<%= SchedulerListeners(listeners) %>
<%= SchedulerCalendars(calendars) %>
<br style="clear:both"/>
<%= SchedulerJobGroups(jobGroups) %>
Expand Down Expand Up @@ -252,7 +255,7 @@ Public Module Views
</html>
End Function

Public Function JobGroup(group As String, paused As Boolean, highlight As String, thisUrl As String, jobs As IEnumerable(Of JobWithContext)) As XElement
Public Function JobGroup(group As String, paused As Boolean?, highlight As String, thisUrl As String, jobs As IEnumerable(Of JobWithContext)) As XElement
Dim schedulerOp = Function(method As String) "scheduler.ashx?method=" + method +
"&groupName=" + group +
"&next=" + HttpUtility.UrlEncode(thisUrl)
Expand All @@ -265,7 +268,7 @@ Public Module Views
<body>
<a href="index.ashx">Index</a>
<h1>Job group <%= group %></h1>
Status: <%= If(paused, "paused", "started") %>
Status: <%= IfNullable(paused, ifNull:="N/A", ifTrue:="paused", ifFalse:="started") %>
<%= If(paused,
SimpleForm(schedulerOp("ResumeJobGroup"), "Resume this job group"),
SimpleForm(schedulerOp("PauseJobGroup"), "Pause this job group")) %>
Expand Down
16 changes: 13 additions & 3 deletions QuartzNetWebConsole/Controllers/IndexController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
using System.Web;
using MiniMVC;
using Quartz;
using QuartzNetWebConsole.Utils;
using QuartzNetWebConsole.Views;

namespace QuartzNetWebConsole.Controllers {
public class IndexController {
private static IScheduler scheduler {
private static ISchedulerWrapper scheduler {
get {
return Setup.Scheduler();
return new SchedulerWrapper(Setup.Scheduler());
}
}

Expand All @@ -34,7 +35,16 @@ public static void Execute(HttpContextBase context) {
.Select(j => Helpers.KV(j.Name, j.GetType()))
.ToArray();

var view = Views.Views.IndexPage(scheduler, scheduler.GetMetaData(), triggerGroups, jobGroups, calendars, jobListeners, triggerListeners);
var view = Views.Views.IndexPage(
schedulerName: scheduler.SchedulerName,
inStandby: scheduler.InStandbyMode,
listeners: scheduler.ListenerManager.GetSchedulerListeners(),
metadata:scheduler.GetMetaData(),
triggerGroups: triggerGroups,
jobGroups: jobGroups,
calendars: calendars,
jobListeners: jobListeners,
triggerListeners: triggerListeners);
context.Response.Html(Helpers.XHTML(view));
}
}
Expand Down
5 changes: 3 additions & 2 deletions QuartzNetWebConsole/Controllers/JobGroupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
using MiniMVC;
using Quartz;
using Quartz.Impl.Matchers;
using QuartzNetWebConsole.Utils;
using QuartzNetWebConsole.Views;

namespace QuartzNetWebConsole.Controllers {
public class JobGroupController {
private static IScheduler scheduler {
private static ISchedulerWrapper scheduler {
get {
return Setup.Scheduler();
return new SchedulerWrapper(Setup.Scheduler());
}
}

Expand Down
1 change: 1 addition & 0 deletions QuartzNetWebConsole/QuartzNetWebConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<Compile Include="Setup.cs" />
<Compile Include="Controllers\StaticController.cs" />
<Compile Include="Controllers\TriggerGroupController.cs" />
<Compile Include="Utils\ISchedulerWrapper.cs" />
<Compile Include="Utils\LimitedList.cs" />
<Compile Include="Utils\SchedulerWrapper.cs" />
</ItemGroup>
Expand Down
41 changes: 41 additions & 0 deletions QuartzNetWebConsole/Utils/ISchedulerWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using Quartz;
using Quartz.Collection;
using Quartz.Impl.Matchers;

namespace QuartzNetWebConsole.Utils {
public interface ISchedulerWrapper {
void Shutdown();
void Start();
void Standby();
void PauseAll();
void ResumeAll();
void ResumeJobGroup(string groupName);
void ResumeTriggerGroup(string groupName);
void PauseJobGroup(string groupName);
void PauseTriggerGroup(string groupName);
void RemoveGlobalJobListener(string name);
void RemoveGlobalTriggerListener(string name);
void DeleteJob(string jobName, string groupName);
void PauseJob(string jobName, string groupName);
void ResumeJob(string jobName, string groupName);
void TriggerJob(string jobName, string groupName);
void Interrupt(string jobName, string groupName);
void ResumeTrigger(string triggerName, string groupName);
void PauseTrigger(string triggerName, string groupName);
void UnscheduleJob(string triggerName, string groupName);
bool? IsJobGroupPaused(string groupName);
bool? IsTriggerGroupPaused(string groupName);
IEnumerable<IJobExecutionContext> GetCurrentlyExecutingJobs();
ISet<JobKey> GetJobKeys(GroupMatcher<JobKey> key);
IJobDetail GetJobDetail(JobKey key);
IEnumerable<string> GetTriggerGroupNames();
IEnumerable<string> GetJobGroupNames();
IEnumerable<string> GetCalendarNames();
IListenerManager ListenerManager { get; }
string SchedulerName { get; }
bool InStandbyMode { get; }
ICalendar GetCalendar(string name);
SchedulerMetaData GetMetaData();
}
}
70 changes: 69 additions & 1 deletion QuartzNetWebConsole/Utils/SchedulerWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using Quartz;
using Quartz.Collection;
using Quartz.Impl.Matchers;

namespace QuartzNetWebConsole.Utils {
public class SchedulerWrapper {
public class SchedulerWrapper : ISchedulerWrapper {
private readonly IScheduler scheduler;

public SchedulerWrapper(IScheduler scheduler) {
Expand Down Expand Up @@ -85,5 +87,71 @@ public void PauseTrigger(string triggerName, string groupName) {
public void UnscheduleJob(string triggerName, string groupName) {
scheduler.UnscheduleJob(new TriggerKey(triggerName, groupName));
}

public bool? IsJobGroupPaused(string groupName) {
try {
return scheduler.IsJobGroupPaused(groupName);
} catch (NotImplementedException) {
return null;
}
}

public bool? IsTriggerGroupPaused(string groupName) {
try {
return scheduler.IsTriggerGroupPaused(groupName);
} catch (NotImplementedException) {
return null;
}
}

public IEnumerable<IJobExecutionContext> GetCurrentlyExecutingJobs() {
return scheduler.GetCurrentlyExecutingJobs();
}

public ISet<JobKey> GetJobKeys(GroupMatcher<JobKey> key) {
return scheduler.GetJobKeys(key);
}

public IJobDetail GetJobDetail(JobKey key) {
return scheduler.GetJobDetail(key);
}

public IEnumerable<string> GetTriggerGroupNames() {
return scheduler.GetTriggerGroupNames();
}

public IEnumerable<string> GetJobGroupNames() {
return scheduler.GetJobGroupNames();
}

public IEnumerable<string> GetCalendarNames() {
return scheduler.GetCalendarNames();
}

public IListenerManager ListenerManager {
get {
return scheduler.ListenerManager;
}
}

public ICalendar GetCalendar(string name) {
return scheduler.GetCalendar(name);
}

public SchedulerMetaData GetMetaData() {
return scheduler.GetMetaData();
}

public string SchedulerName {
get {
return scheduler.SchedulerName;
}
}

public bool InStandbyMode {
get {
return scheduler.InStandbyMode;
}
}
}
}

0 comments on commit a43573b

Please sign in to comment.