Invoking Quartz Job from controller

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Invoking Quartz Job from controller

Richard Paul
I'm attempting to create a little status controller for an admin tool
that shows all available quartz tasks (as configured by the Grails
Quartz plugin) and allows the user to trigger a task.
I have the task listing working using:

def groupName = 'GRAILS_JOBS'
def index = {
  def triggers = quartzScheduler.getTriggerNames(groupName).collect {
triggerName ->
    quartzScheduler.getTrigger(triggerName, groupName)
  }
  [triggers:triggers]
}

In the HTML I've created a button to trigger a task (along with the
trigger name and next firetime), currently this passes through a
parameter called job which is equal to the trigger's name.  The quartz
plugin set the trigger name to the package and class of the related
job, e.g. example.MyJob

<!-- for each trigger -->
<form action='run' method='post'>
  <input type='hidden' name='job' value='${trigger.jobName}'/><!--
e.g. example.MyJob -->
  <input type='submit' value='Run now'/>
</form>

A quartz job can be triggered manually by calling MyJob.triggerNow()

I'm attempting to trigger this dynamically by invoking:

def run = {
  def job = params.job
  Eval.me(job + '.triggerNow()')
}

This outputs:

groovy.lang.MissingPropertyException: No such property: example for
class: Script1
  at Script1.run(Script1.groovy:1)
  at example.status.controller.StatusController$_closure2.doCall(StatusController.groovy:26)

I'm guessing what's happening is that the script binding used by
Eval.me doesn't have access to all the classes it normally has for
security reasons?

My question is this, can someone suggest a simple way to trigger a job
from my status controller.  Bonus points if it can be done in a more
secure way.

Thanks in advance,
Richard

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Invoking Quartz Job from controller

Sergey Nebolsin
import org.codehaus.groovy.grails.plugins.quartz.GrailsTaskClassProperty as GTCP
// import org.codehaus.groovy.grails.plugins.quartz.GrailsJobClassProperty as GJCP // if you're using latest snapshot from the GitHub

quartzScheduler.triggerJob(job, GTCP.DEFAULT_GROUP, params ? new JobDataMap(params) : null)

On Tue, Nov 9, 2010 at 19:15, Richard Paul <[hidden email]> wrote:
I'm attempting to create a little status controller for an admin tool
that shows all available quartz tasks (as configured by the Grails
Quartz plugin) and allows the user to trigger a task.
I have the task listing working using:

def groupName = 'GRAILS_JOBS'
def index = {
 def triggers = quartzScheduler.getTriggerNames(groupName).collect {
triggerName ->
   quartzScheduler.getTrigger(triggerName, groupName)
 }
 [triggers:triggers]
}

In the HTML I've created a button to trigger a task (along with the
trigger name and next firetime), currently this passes through a
parameter called job which is equal to the trigger's name.  The quartz
plugin set the trigger name to the package and class of the related
job, e.g. example.MyJob

<!-- for each trigger -->
<form action='run' method='post'>
 <input type='hidden' name='job' value='${trigger.jobName}'/><!--
e.g. example.MyJob -->
 <input type='submit' value='Run now'/>
</form>

A quartz job can be triggered manually by calling MyJob.triggerNow()

I'm attempting to trigger this dynamically by invoking:

def run = {
 def job = params.job
 Eval.me(job + '.triggerNow()')
}

This outputs:

groovy.lang.MissingPropertyException: No such property: example for
class: Script1
 at Script1.run(Script1.groovy:1)
 at example.status.controller.StatusController$_closure2.doCall(StatusController.groovy:26)

I'm guessing what's happening is that the script binding used by
Eval.me doesn't have access to all the classes it normally has for
security reasons?

My question is this, can someone suggest a simple way to trigger a job
from my status controller.  Bonus points if it can be done in a more
secure way.

Thanks in advance,
Richard

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





--
Sergey Nebolsin
Chief Technical Officer
Prophotos.ru, Bestphotographer.ru
Reply | Threaded
Open this post in threaded view
|

Re: Invoking Quartz Job from controller

Sergey Nebolsin
In reply to this post by Richard Paul
And it also should work this way (not tested though):

grailsApplication.classLoader.loadClass(job).triggerNow()

On Tue, Nov 9, 2010 at 19:15, Richard Paul <[hidden email]> wrote:
I'm attempting to create a little status controller for an admin tool
that shows all available quartz tasks (as configured by the Grails
Quartz plugin) and allows the user to trigger a task.
I have the task listing working using:

def groupName = 'GRAILS_JOBS'
def index = {
 def triggers = quartzScheduler.getTriggerNames(groupName).collect {
triggerName ->
   quartzScheduler.getTrigger(triggerName, groupName)
 }
 [triggers:triggers]
}

In the HTML I've created a button to trigger a task (along with the
trigger name and next firetime), currently this passes through a
parameter called job which is equal to the trigger's name.  The quartz
plugin set the trigger name to the package and class of the related
job, e.g. example.MyJob

<!-- for each trigger -->
<form action='run' method='post'>
 <input type='hidden' name='job' value='${trigger.jobName}'/><!--
e.g. example.MyJob -->
 <input type='submit' value='Run now'/>
</form>

A quartz job can be triggered manually by calling MyJob.triggerNow()

I'm attempting to trigger this dynamically by invoking:

def run = {
 def job = params.job
 Eval.me(job + '.triggerNow()')
}

This outputs:

groovy.lang.MissingPropertyException: No such property: example for
class: Script1
 at Script1.run(Script1.groovy:1)
 at example.status.controller.StatusController$_closure2.doCall(StatusController.groovy:26)

I'm guessing what's happening is that the script binding used by
Eval.me doesn't have access to all the classes it normally has for
security reasons?

My question is this, can someone suggest a simple way to trigger a job
from my status controller.  Bonus points if it can be done in a more
secure way.

Thanks in advance,
Richard

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





--
Sergey Nebolsin
Chief Technical Officer
Prophotos.ru, Bestphotographer.ru
Reply | Threaded
Open this post in threaded view
|

Re: Invoking Quartz Job from controller

Richard Paul
Worked a charm, thanks Sergey.  Option 2 looks interesting but option
1 is exactly what I needed.
I'll have to investigate how the Job classes tie into the triggers a
bit closer to understand how this works.

On 9 November 2010 16:41, Sergey Nebolsin <[hidden email]> wrote:

> And it also should work this way (not tested though):
> grailsApplication.classLoader.loadClass(job).triggerNow()
>
> On Tue, Nov 9, 2010 at 19:15, Richard Paul <[hidden email]> wrote:
>>
>> I'm attempting to create a little status controller for an admin tool
>> that shows all available quartz tasks (as configured by the Grails
>> Quartz plugin) and allows the user to trigger a task.
>> I have the task listing working using:
>>
>> def groupName = 'GRAILS_JOBS'
>> def index = {
>>  def triggers = quartzScheduler.getTriggerNames(groupName).collect {
>> triggerName ->
>>    quartzScheduler.getTrigger(triggerName, groupName)
>>  }
>>  [triggers:triggers]
>> }
>>
>> In the HTML I've created a button to trigger a task (along with the
>> trigger name and next firetime), currently this passes through a
>> parameter called job which is equal to the trigger's name.  The quartz
>> plugin set the trigger name to the package and class of the related
>> job, e.g. example.MyJob
>>
>> <!-- for each trigger -->
>> <form action='run' method='post'>
>>  <input type='hidden' name='job' value='${trigger.jobName}'/><!--
>> e.g. example.MyJob -->
>>  <input type='submit' value='Run now'/>
>> </form>
>>
>> A quartz job can be triggered manually by calling MyJob.triggerNow()
>>
>> I'm attempting to trigger this dynamically by invoking:
>>
>> def run = {
>>  def job = params.job
>>  Eval.me(job + '.triggerNow()')
>> }
>>
>> This outputs:
>>
>> groovy.lang.MissingPropertyException: No such property: example for
>> class: Script1
>>  at Script1.run(Script1.groovy:1)
>>  at
>> example.status.controller.StatusController$_closure2.doCall(StatusController.groovy:26)
>>
>> I'm guessing what's happening is that the script binding used by
>> Eval.me doesn't have access to all the classes it normally has for
>> security reasons?
>>
>> My question is this, can someone suggest a simple way to trigger a job
>> from my status controller.  Bonus points if it can be done in a more
>> secure way.
>>
>> Thanks in advance,
>> Richard
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>
>
> --
> Sergey Nebolsin
> Chief Technical Officer
> Prophotos.ru, Bestphotographer.ru
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email