2

I am currently running Quartz under spring using the configuration below. The reason for using a database as a backend for the scheduler is to enable clustered mode.

This all works fine, but if I want to remove the InitialAbstractPublicationJob I have problems. Let's say I delete all of the config below, except for the scheduler itself. A row still exists in the DB table QRTZ_TRIGGERS.

  TRIGGER_NAME: initialAbstractTrigger
 TRIGGER_GROUP: DEFAULT
      JOB_NAME: initialAbstractDataAccessDelegator
     JOB_GROUP: DEFAULT
   IS_VOLATILE: 0
   DESCRIPTION: NULL
NEXT_FIRE_TIME: 1330953433511
PREV_FIRE_TIME: 1330953432511
 TRIGGER_STATE: WAITING
  TRIGGER_TYPE: SIMPLE
    START_TIME: 1330953336511
      END_TIME: 0
 CALENDAR_NAME: NULL
 MISFIRE_INSTR: 0
      JOB_DATA: NULL
1 row in set (0.00 sec)

This row causes quartz to try and load the AbstractPublicationJobBean which no longer exists in spring, and exceptions abound. So my question is: is it possible to configure the scheduler to flush triggers from the DB at shutdown or startup of spring, and recreate the triggers from the spring applicationContext.xml

<bean id="initialAbstractPublicationJob" class="bbc.forge.ibroadcast.snowball.InitialAbstractPublicationJob" />
<bean id="initialAbstractDataAccessDelegator" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="bbc.forge.ibroadcast.snowball.DelegatingJobBean"/>
    <property name="durability" value="false" />
    <property name="jobDataAsMap">
        <map>
            <entry key="job.bean.name" value="initialAbstractPublicationJob" >
            </entry>
            <entry key="sdtl.file.prefix" value="sdtl_" >
            </entry>
        </map>
    </property>
</bean>
<bean id="initialAbstractTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
     see the example of method invoking job above 
    <property name="jobDetail" ref="initialAbstractDataAccessDelegator" />
     10 seconds 
    <property name="startDelay" value="0" />
     repeat every n milliseconds 
    <property name="repeatInterval" value="1000" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="initialAbstractTrigger" />
        </list>
    </property>
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
    <property name="applicationContextSchedulerContextKey">
        <value>applicationContext</value>
    </property>
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.jobStore.isClustered">true</prop>
            <prop key="org.quartz.scheduler.instanceId">AUTO</prop>


        </props>
    </property>

</bean>
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
clumsyjedi
  • 477
  • 6
  • 15

2 Answers2

1

duplicate question: delete-trigger-in-quartz

if you want to update trigger when spring shutdown, just do these things in a @PreDestroy method.

Community
  • 1
  • 1
Mike Lin
  • 370
  • 1
  • 9
1

You can use XMLSchedulingDataProcessorPlugin to store jobs and triggers configuration in a separate XML file. This file can overwrite existing jobs on startup:

<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation=" http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_2_0.xsd ">

    <processing-directives>
        <overwrite-existing-data>true</overwrite-existing-data>
        <ignore-duplicates>true</ignore-duplicates>
    </processing-directives>

</job-scheduling-data>

A little bit more on the plugin can be found in Configure Scheduler Plugins documentation reference.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674