Quartz Plugin

Grails Job doesn't reload on a change

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.2
  • Fix Version/s: 0.3
  • Component/s: None
  • Labels:
    None
  • Environment:
    Window, Java 1.5, Grails 1.0 RC2, Grails Quarz 0.2

Description

It appears as though grails jobs are not reloaded when the job is changed.

created a job with a simple println,

started the app (grails run-app)

saw the output,

changed the println and saved.

the output did not change.

Activity

Hide
Wolfgang Schell added a comment -

This is caused by the quartz scheduler being shut down.

When the job class is reloaded, the bean factory, which created the scheduler is destroyed. This leads to the scheduler being shut down, which in turn prohibits (re-)scheduling jobs.

This happens in QuartzGrailsPlugin.groovy:123:

def onChange = { event ->
...
event.ctx.registerBeanDefinition("${fullName}", beans.getBeanDefinition("${fullName}"))
...
}

Show
Wolfgang Schell added a comment - This is caused by the quartz scheduler being shut down. When the job class is reloaded, the bean factory, which created the scheduler is destroyed. This leads to the scheduler being shut down, which in turn prohibits (re-)scheduling jobs. This happens in QuartzGrailsPlugin.groovy:123: def onChange = { event -> ... event.ctx.registerBeanDefinition("${fullName}", beans.getBeanDefinition("${fullName}")) ... }
Hide
Wolfgang Schell added a comment -

After some debugging, I found out, that the problem ist not the BeanFactory being destroyed, but rather the scheduler being destroyed because it is registered as a dependency to the <MyJobClass>Trigger class (see methods registerDependentBean() and destroySingleton() of org.springframework.beans.factory.support.DefaultSingletonBeanRegistry).

The solution is to avoid these dependencies by delaying the registration of the job triggers. The attached patch registers the job triggers in doWithApplicationContext() instead of doWithSpring().

Changed and newly created jobs are now created/updated correctly without the scheduler being shut down.

One issue remains: If an existing job is deleted (e.g: rm grails-app/jobs/MyJob.groovy), the job will still be running.
I Haven't investigated this issue properly, but I think this is rather a problem of the resource watcher. Maybe deleted resource events are not propagated to onChange()?

Show
Wolfgang Schell added a comment - After some debugging, I found out, that the problem ist not the BeanFactory being destroyed, but rather the scheduler being destroyed because it is registered as a dependency to the <MyJobClass>Trigger class (see methods registerDependentBean() and destroySingleton() of org.springframework.beans.factory.support.DefaultSingletonBeanRegistry). The solution is to avoid these dependencies by delaying the registration of the job triggers. The attached patch registers the job triggers in doWithApplicationContext() instead of doWithSpring(). Changed and newly created jobs are now created/updated correctly without the scheduler being shut down. One issue remains: If an existing job is deleted (e.g: rm grails-app/jobs/MyJob.groovy), the job will still be running. I Haven't investigated this issue properly, but I think this is rather a problem of the resource watcher. Maybe deleted resource events are not propagated to onChange()?
Hide
Sergey Nebolsin added a comment -

Patch applied, thank you.

Show
Sergey Nebolsin added a comment - Patch applied, thank you.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: