<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Programatically Scheduling Jobs in Grails with Quartz</title>
	<atom:link href="http://robjam.es/2009/12/programatically-scheduling-jobs-in-grails-with-quartz/feed/" rel="self" type="application/rss+xml" />
	<link>http://robjam.es/2009/12/programatically-scheduling-jobs-in-grails-with-quartz/</link>
	<description>Now What?</description>
	<lastBuildDate>Thu, 10 Jun 2010 18:12:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Rob James</title>
		<link>http://robjam.es/2009/12/programatically-scheduling-jobs-in-grails-with-quartz/comment-page-1/#comment-17853</link>
		<dc:creator>Rob James</dc:creator>
		<pubDate>Tue, 06 Apr 2010 21:22:45 +0000</pubDate>
		<guid isPermaLink="false">http://robjam.es/?p=236#comment-17853</guid>
		<description>Danny/Dennis, the issue is that when using this method of running a quartz job, the job itself is disconnected from your session and therefore none of the datasource or services become available to you.

To get it to work, you need to inject the hibernate session through the spring config. And I found this to be a bit painful. I can&#039;t find the references, but do a Google search. But this page helped me quite a lot http://stackoverflow.com/questions/1860572/grails-quartz-job-has-no-hibernate-session-after-upgrade-causing-lazyinitializat (same kind of issue)

For my purposes, I went back to creating the jobs and could use the MyJob.schedule() methods effectively to schedule my jobs programmatically. The other issue I had to overcome was remove any triggers at startup and I discovered that it was as simple as;
static triggers = {}
ie/ pass an empty triggers object!!</description>
		<content:encoded><![CDATA[<p>Danny/Dennis, the issue is that when using this method of running a quartz job, the job itself is disconnected from your session and therefore none of the datasource or services become available to you.</p>
<p>To get it to work, you need to inject the hibernate session through the spring config. And I found this to be a bit painful. I can&#8217;t find the references, but do a Google search. But this page helped me quite a lot <a href="http://stackoverflow.com/questions/1860572/grails-quartz-job-has-no-hibernate-session-after-upgrade-causing-lazyinitializat" rel="nofollow">http://stackoverflow.com/questions/1860572/grails-quartz-job-has-no-hibernate-session-after-upgrade-causing-lazyinitializat</a> (same kind of issue)</p>
<p>For my purposes, I went back to creating the jobs and could use the MyJob.schedule() methods effectively to schedule my jobs programmatically. The other issue I had to overcome was remove any triggers at startup and I discovered that it was as simple as;<br />
static triggers = {}<br />
ie/ pass an empty triggers object!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dennis Carroll</title>
		<link>http://robjam.es/2009/12/programatically-scheduling-jobs-in-grails-with-quartz/comment-page-1/#comment-17852</link>
		<dc:creator>Dennis Carroll</dc:creator>
		<pubDate>Fri, 02 Apr 2010 15:53:53 +0000</pubDate>
		<guid isPermaLink="false">http://robjam.es/?p=236#comment-17852</guid>
		<description>Thanks for the insight.  Your basic example worked very well for me.  I extended my service with another method that accesses the database via injected dataSource and groovy.sql.Sql. I found the dataSource to be null when this method was called from the execute method.  When the service method was called directly from an integration test or from the controller (before or after the scheduleJob call) the dataSource was initialized and worked as expected.

I have no idea how to find the cause but have a simple demonstration example I could pass along.</description>
		<content:encoded><![CDATA[<p>Thanks for the insight.  Your basic example worked very well for me.  I extended my service with another method that accesses the database via injected dataSource and groovy.sql.Sql. I found the dataSource to be null when this method was called from the execute method.  When the service method was called directly from an integration test or from the controller (before or after the scheduleJob call) the dataSource was initialized and worked as expected.</p>
<p>I have no idea how to find the cause but have a simple demonstration example I could pass along.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny</title>
		<link>http://robjam.es/2009/12/programatically-scheduling-jobs-in-grails-with-quartz/comment-page-1/#comment-17851</link>
		<dc:creator>Danny</dc:creator>
		<pubDate>Tue, 30 Mar 2010 13:48:19 +0000</pubDate>
		<guid isPermaLink="false">http://robjam.es/?p=236#comment-17851</guid>
		<description>Hi,

I have implemented this example as I need to be able to create jobs at runtime but I am having problems with the service which implements Job.

The problem is that I cannot inject any of my services or grailsApplication in to it, I get the error cannot invoke &#039;myMethod&#039; on a null object or cannot get property &#039;metadata&#039; on a null object.

My code is:

import org.quartz.Job
import org.quartz.JobExecutionContext

class ReplenishmentService implements Job {

  boolean transactional = false
  def grailsApplication

  void execute(JobExecutionContext jobExecutionContext) {

    println grailsApplication.metadata[&#039;app.name&#039;]
  }
}</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I have implemented this example as I need to be able to create jobs at runtime but I am having problems with the service which implements Job.</p>
<p>The problem is that I cannot inject any of my services or grailsApplication in to it, I get the error cannot invoke &#8216;myMethod&#8217; on a null object or cannot get property &#8216;metadata&#8217; on a null object.</p>
<p>My code is:</p>
<p>import org.quartz.Job<br />
import org.quartz.JobExecutionContext</p>
<p>class ReplenishmentService implements Job {</p>
<p>  boolean transactional = false<br />
  def grailsApplication</p>
<p>  void execute(JobExecutionContext jobExecutionContext) {</p>
<p>    println grailsApplication.metadata['app.name']<br />
  }<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
