Permalink
Browse files

Cron trigger reschedule interface

  • Loading branch information...
1 parent 7a0221e commit c0f00550dc608eaa6824b7cee22cc807dbcba35f @zoran119 zoran119 committed with May 2, 2013
@@ -3,6 +3,9 @@ package org.grails.plugins.quartz
import org.quartz.Scheduler
import org.quartz.Trigger
import org.quartz.impl.matchers.GroupMatcher
+import org.quartz.TriggerKey
+import org.quartz.CronExpression
+import org.quartz.CronTrigger
import static org.quartz.impl.matchers.GroupMatcher.jobGroupEquals
@@ -119,4 +122,39 @@ class QuartzController {
redirect(action: "list")
}
+ def editCronTrigger = {
+ def trigger = quartzScheduler.getTrigger(new TriggerKey(params.triggerName, params.triggerGroup))
+ if (!(trigger instanceof org.quartz.CronTrigger)) {
+ flash.message = "This trigger is not a cron trigger"
+ redirect(action: "list")
+ return
+ }
+ [trigger: trigger]
+ }
+
+ def saveCronTrigger = {
+ if (!params.triggerName || !params.triggerGroup) {
+ flash.message = "Invalid trigger parameters"
+ redirect(action: "list")
+ return
+ }
+
+ CronTrigger trigger = quartzScheduler.getTrigger(new TriggerKey(params.triggerName, params.triggerGroup))
+ if (!trigger) {
+ flash.message = "No such trigger"
+ redirect(action: "list")
+ return
+ }
+
+ try {
+ trigger.setCronExpression(params.cronexpression)
+ quartzScheduler.rescheduleJob(new TriggerKey(params.triggerName, params.triggerGroup), trigger);
+ } catch(Exception ex) {
+ flash.message = "cron expression (${params.cronexpression}) was not correct"
+ render(view: "editCronTrigger", model: [trigger: trigger])
+ return
+ }
+ redirect(action: "list")
+ }
+
}
@@ -0,0 +1,40 @@
+<%@ page import="org.quartz.Trigger" %>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <g:set var="layoutName" value="${grailsApplication.config.quartz?.monitor?.layout}" />
+ <meta name="layout" content="${layoutName ?: 'main'}" />
+ <title>Quartz Jobs - Reschedule</title>
+ <link rel="stylesheet" href="${resource(dir: 'css', file: 'quartz-monitor.css', plugin: 'quartz-monitor')}"/>
+ <link rel="stylesheet" href="${resource(dir: 'css', file: 'jquery.countdown.css', plugin: 'quartz-monitor')}"/>
+ <link rel="stylesheet" href="${resource(dir: 'css', file: 'jquery.clock.css', plugin: 'quartz-monitor')}"/>
+ </head>
+ <body>
+ <div class="content">
+ <div class="nav">
+ <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
+ </div>
+ <div class="body">
+ <g:if test="${flash.message}">
+ <div class="message">${flash.message}</div>
+ </g:if>
+ <h1 id="quartz-title">Reschedule [${trigger.name}]</h1>
+ <g:form action="saveCronTrigger">
+ <g:hiddenField name="triggerName" value="${trigger.name}"/>
+ <g:hiddenField name="triggerGroup" value="${trigger.group}"/>
+ <fieldset class="form">
+ <div>
+ <label>Cron Expression</label>
+ <span class="required-indicator">*</span>
+ <g:textField name="cronexpression" value="${trigger.getCronExpression()}"/>
+ </div>
+ </fieldset>
+ <fieldset class="buttons">
+ <g:submitButton name="save" value="Reschedule"/>
+ <g:actionSubmit action="list" name="cancel" value="Cancel"/>
+ </fieldset>
+ </g:form>
+ </div>
+ </div>
+ </body>
+</html>
@@ -74,6 +74,9 @@
<a href="<g:createLink action="start" params="[jobName:job.name, jobGroup:job.group]"/>"><img class="quartz-tooltip" data-tooltip="Start job schedule" src="<g:resource dir="images" file="start.png" plugin="quartz-monitor"/>"></a>
</g:else>
<a href="<g:createLink action="runNow" params="[jobName:job.name, jobGroup:job.group]"/>"><img class="quartz-tooltip" data-tooltip="Run now" src="<g:resource dir="images" file="run.png" plugin="quartz-monitor"/>"></a>
+ <g:if test="${job.trigger instanceof org.quartz.CronTrigger}">
+ <a href="<g:createLink action="editCronTrigger" params="[triggerName:job.trigger.name, triggerGroup:job.trigger.group]"/>"><img class="quartz-tooltip" data-tooltip="Reschedule" src="<g:resource dir="images" file="reschedule.png" plugin="quartz-monitor"/>"></a>
+ </g:if>
</g:if>
</td>
</tr>

0 comments on commit c0f0055

Please sign in to comment.