Hi all,
I recently set up some Quartz jobs in my app using the cron syntax, but I'm confused about how I can run these jobs on-demand via a script. I understand that there is a triggerNow() method that does this, but I don't understand how I can this from a script. This is what I was trying to do with a Gant script: includeTargets << grailsScript("_GrailsBootstrap") target(main: "Example script") { depends( bootstrap ) def clazz = classLoader.loadClass('org.example.ExampleQuartzJob') clazz.triggerNow() } setDefaultTarget(main) I run this in my pseudo-production environment and I get this: Environment set to production [groovyc] Compiling 1 source file [groovyc] Compiling 1 source file Application context shutting down... Application context shutdown. The Quartz job actually calls another service inside my Grails app and that service uses the Domains/Data Source. Do I need to inform Gant of other dependencies? Is Gant even the correct way to do this? It seemed like the simplest way to get access to your Grails app from a script, but I'm new to this so any help is appreciated even if it's not Gant. Regards, Sean |
Try 'grails run-script' or batch-launcher plugin.
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
In reply to this post by dynis
grails batch-run-app
or grails batch-run-app --args=test_job.Job3Job I think it is also doable using 'grails run-script'. You can also use launcher to start a regular command line java app. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
In reply to this post by Daniel Henrique Alves Lima
Thanks for the tip Daniel. That looks like a far more sensible way to run my script.
The quartz job itself still doesn't seem to run correctly from my script (no errors, it just doesn't seem to execute). The code is effectively the same as what I originally posted, I just removed the Gant-specific portions. Luckily the job is just calling a service anyway so I can just call the service from my script in this instance. I'd be interested to know why I can't seem to trigger a quartz job from this script, so if anyone has any examples I would appreciate it. Otherwise I'll just run with what I have. Thanks! Sean |
In reply to this post by Daniel Henrique Alves Lima
Looks like we crossed posts there. Thanks for the example Daniel! I'll give this a try and see if I have any more success.
Thanks! Sean |
In reply to this post by Daniel Henrique Alves Lima
I tested out the test_job app and running it normally (grails run-app) works fine. The code inside Bootstrap.groovy fires off and the println's show the threads working. But if I copy the same code into a script and kick it off (grails run-script) I don't see the println statements at all:
def jobClass = this.class.classLoader.loadClass('test_job.Job3Job') jobClass.triggerNow([:]) while (true) { Thread.sleep(10000) } This is roughly the same behavior I got using my own jobs (I don't see the println's and my database inserts don't occur). Does this same loadClass/triggerNow approach work for you using run-script? Thank you so much for your help so far; I'm really starting to feel good about Grails. :) Regards, Sean |
In reply to this post by dynis
Hi, Sean.
I'm not sure if 'grails run-script' will start Quartz plugin. I don't know this script very well. Maybe Ted (http://naleid.com/blog/2010/12/03/grails-run-script-updated-for-grails-1-3-5/) or another Grails developer/contributor can be more helpful here. As a temporary workaround (or a definitive solution), can't you use Quartz + Batch Launcher, like the sample that I've sent? You use it as it is or you can import the targets of BatchRunApp.groovy or _BatchRun.groovy in your own script. Best regards, Daniel. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
May I suggest a different approach? What *exactly* do you need to do?
I would suggest you starting a single instance of Grails and configuring different jobs using Quartz cron expressions... Daniel Henrique Alves Lima wrote: > Hi, Sean. > > I'm not sure if 'grails run-script' will start Quartz plugin. > I don't know this script very well. Maybe Ted > (http://naleid.com/blog/2010/12/03/grails-run-script-updated-for-grails-1-3-5/) > or another Grails developer/contributor can be more helpful here. > As a temporary workaround (or a definitive solution), can't > you use Quartz + Batch Launcher, like the sample that I've sent? You > use it as it is or you can import the targets of BatchRunApp.groovy or > _BatchRun.groovy in your own script. > > Best regards, > > Daniel. > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
Hi Daniel,
The Quartz jobs are actually integrated into a larger application. So the application itself can provide a web interface and handle other operations, but the Quartz jobs fire off every so often to handle some mundane processing work (and they're scheduled using the cron expressions to fire off at regular intervals). Basically what I was trying to do is implement a simple way to kick off those same jobs instantly at any time I want by running a script (instead of waiting for the next interval when it would normally run). Because the Batch Launcher seems to execute code from Bootstrap it isn't really the sensible choice in this instance. Using 'grails run-script' actually makes a lot of sense in this instance, but for some reason my approach isn't working. I set the log level to DEBUG and I could actually see that Quartz is loaded when my script runs. I'm not sure why it doesn't work as I expect. The work-around I'm using at the moment is to abstract the job code into a service call and simply call the service call from a script using 'run-script' instead of calling the job itself. This solves my actual problem, I just wish I knew how to gracefully kick off a Quartz job using run-script. Thanks for your help Daniel! Grails run-script helped me get to my solution. :) Regards, Sean |
Hi, Sean.
So you have an webapp running with these jobs set up, right? Can't you: - Create a simple controller that starts the execution of these jobs? I believe your controller/service can use triggerNow or an injected job scheduler; - Use any security plugin to restrict the access to this controller; - Write simple Groovy (non-Grails) scripts that invoke this special (and protected) URL/Controller? My initial suggestion was to use batch launcher to start a single (non-web) Grails app, instead of starting a "new app instance" for each execution, but you already have a running app. Best regards, Daniel. dynis wrote: > Hi Daniel, > > The Quartz jobs are actually integrated into a larger application. So the > application itself can provide a web interface and handle other operations, > but the Quartz jobs fire off every so often to handle some mundane > processing work (and they're scheduled using the cron expressions to fire > off at regular intervals). > > Basically what I was trying to do is implement a simple way to kick off > those same jobs instantly at any time I want by running a script (instead of > waiting for the next interval when it would normally run). > > Because the Batch Launcher seems to execute code from Bootstrap it isn't > really the sensible choice in this instance. Using 'grails run-script' > actually makes a lot of sense in this instance, but for some reason my > approach isn't working. I set the log level to DEBUG and I could actually > see that Quartz is loaded when my script runs. I'm not sure why it doesn't > work as I expect. > > The work-around I'm using at the moment is to abstract the job code into a > service call and simply call the service call from a script using > 'run-script' instead of calling the job itself. This solves my actual > problem, I just wish I knew how to gracefully kick off a Quartz job using > run-script. > > Thanks for your help Daniel! Grails run-script helped me get to my > solution. :) > > Regards, > Sean > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
An alternative approach:
http://techdm.com/grails/?p=371&lang=en Best regards, Daniel. Daniel Henrique Alves Lima wrote: > Hi, Sean. > > So you have an webapp running with these jobs set up, right? Can't you: > > - Create a simple controller that starts the execution of these jobs? > I believe your controller/service can use triggerNow or an injected > job scheduler; > - Use any security plugin to restrict the access to this controller; > - Write simple Groovy (non-Grails) scripts that invoke this special > (and protected) URL/Controller? > > My initial suggestion was to use batch launcher to start a single > (non-web) Grails app, instead of starting a "new app instance" for > each execution, but you already have a running app. > > Best regards, > > Daniel. > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
Just saw this thread.
I had a similar problem and found a little UI that somebody put together (in Java - I adopted it for Grails). See attached gsp file. It shows me all my existing jobs and allows me to fire any job I want before its time to execute. I have some jobs that I want to kick off manually, so I just chedule them several months in advance, and kick them off manually - works like a charm and generally provides a more visual way to remember which Controller does need to pass in anything, all lookups happen in the gsp: UtilController.groovy def jobs = { [ ] } This is extremely useful, would be great to add this to the quartz plugin by default (or as another plugin). Of course, make sure to secure the path to the action. Thanks, Jean On Sun, Jun 5, 2011 at 8:26 PM, Daniel Henrique Alves Lima <[hidden email]> wrote: An alternative approach: --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
Free forum by Nabble | Edit this page |