Created
March 26, 2014 15:49
-
-
Save sirdsoriano/9786477 to your computer and use it in GitHub Desktop.
A very simple grails quartz2 monitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h3>Jobs</h3> | |
Current time:${new Date()} | |
<g:form controller="quartz"> | |
<g:actionSubmit action="pauseAll" value="Pause all Jobs"/> | |
<g:actionSubmit action="resumeAll" value="Resume all Jobs"/> | |
</g:form> | |
<table> | |
<thead> | |
<tr> | |
<th>JobKey</th> | |
<th>State</th> | |
<th>FireTime</th> | |
<th>NextFireTime</th> | |
<th>Last run</th> | |
<th>Actions</th> | |
</tr> | |
</thead> | |
<tbody> | |
<g:each in="${jobs.keySet()}" var="${jobKey}"> | |
<g:set var="job" value="${jobs[jobKey]}" /> | |
<g:each in="${job.triggers}" var="${trigger}"> | |
<tr> | |
<td>${(jobKey.toString().split(/\./) as List).last()}</td> | |
<td>${trigger.state}</td> | |
<td>${job.executionContext?.fireTime}</td> | |
<td>${trigger.detail.nextFireTime}</td> | |
<td>${job.executionContext?.jobRunTime}</td> | |
<td><g:form controller="quartz"> | |
<g:hiddenField name="jobKey" value="${jobKey.name}" /> | |
<g:hiddenField name="groupName" value="${jobKey.group}" /> | |
<g:actionSubmit action="triggerJob" value="Trigger job" /> | |
<g:actionSubmit action="pauseJob" value="Pause job" /> | |
<g:actionSubmit action="resumeJob" value="Resume job" /> | |
</g:form></td> | |
</tr> | |
</g:each> | |
</g:each> | |
</tbody> | |
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tirant.tolmex.backend.edicion.controllers.admin | |
import grails.plugins.springsecurity.Secured | |
@Secured(["ROLE_ADMIN"]) | |
class QuartzController { | |
static layout = 'admin' | |
def quartzScheduler | |
def index = { | |
def jobGroups = quartzScheduler.getJobGroupNames(); | |
def currentlyExecutingJobs = quartzScheduler.getCurrentlyExecutingJobs() | |
def currentlyExecutingJobsMap = currentlyExecutingJobs.inject([:],{ accum, item -> | |
accum[item.jobDetail.key] = item | |
accum | |
}) | |
def jobs = [:] | |
for (String groupName:jobGroups) | |
{ | |
def jobKeys = quartzScheduler.getJobKeys(org.quartz.impl.matchers.GroupMatcher.groupEquals(groupName)); | |
for (def jobKey:jobKeys) | |
{ | |
def triggers = quartzScheduler.getTriggersOfJob(jobKey).collect({ trigger -> | |
[detail:trigger,state:quartzScheduler.getTriggerState(trigger.key)] | |
}) | |
jobs[jobKey] = [triggers:triggers, groupName:groupName, executionContext: currentlyExecutingJobsMap[jobKey] ] | |
} | |
} | |
[jobs:jobs] | |
} | |
def pauseAll = { | |
quartzScheduler.pauseAll() | |
redirect(action:'index') | |
} | |
def pauseJob = { | |
quartzScheduler.pauseJob(new org.quartz.JobKey(params.jobKey,params.groupName)) | |
redirect(action:'index') | |
} | |
def resumeAll = { | |
quartzScheduler.resumeAll() | |
redirect(action:'index') | |
} | |
def resumeJob = { | |
quartzScheduler.resumeJob(new org.quartz.JobKey(params.jobKey,params.groupName)) | |
redirect(action:'index') | |
} | |
def triggerJob = { | |
quartzScheduler.triggerJob(new org.quartz.JobKey(params.jobKey,params.groupName),null) | |
redirect(action:'index') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment