简体   繁体   中英

How to change schedule of clustered quartz job?

As far as I tried, I have to manually change the CRON_TRIGGERS table in DB. Dirty...

Any way to make more like this?:

  1. There are 2 apps running, both have in .properties file schedule defined as "every minute" and so works the job
  2. I stop one instance and reconfigure (change in .properties file), so the schedule is "every hour"
  3. I start the instance. Now I would like that instace to check, that such job is already defined in DB and to update the schedule there. It is not happening now using configuration from site http://www.objectpartners.com/2013/07/09/configuring-quartz-2-with-spring-in-clustered-mode/

Or what is the typical solution?

  1. So I guess that when you say .properties file, you actually mean the spring bean XML file(s).
  2. It does not make any sense that you statically configure identical jobs with different schedules. If for whatever reason, one instance restarts, it will automatically apply its own schedule. If statically configured, your job triggers should be the same on all instances
  3. If you properly set <property name="overwriteExistingJobs" value="true"/> in your SchedulerFactoryBean it should automatically updates the schedule of the job.
  4. You should never modify the database manually. Always update the scheduler through its API.

Try sth like this:

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="jobDetails">
            <list>
                <ref bean="yourJobDetail" />
            </list>
        </property>
        <property name="triggers">
            <list>
                <ref bean="yourJobTrigger" />
            </list>
        </property>
        <property name="configLocation" value="file:${HOME}/yourProperties.properties" />
        <!-- Commented, because don't work with autocommit = false on spring data source -->
        <!-- <property name="dataSource" ref="mainDataSource"/> -->
        <property name="transactionManager" ref="mainTransactionManager" />
        <property name="autoStartup" value="true" />
        <property name="applicationContextSchedulerContextKey" value="applicationContext" />
        <property name="jobFactory">
            <bean class="FactoryForJobWithInjectionOfSpringBbean" />
        </property>
        <!-- Will update database cron triggers to what is in this jobs file on each deploy. Replaces all previous trigger and job data that 
            was in the database. YMMV -->
        <!-- dont work properly with cluster -->
        <!-- <property name="overwriteExistingJobs" value="true" /> -->
    </bean>

Unfortunately i think that:

<property name="overwriteExistingJobs" value="true" />

dosen't work correctly in cluster mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM