michaelklishin / quartz-mongodb

A MongoDB-based store for the Quartz scheduler. This fork strives to be as feature complete as possible. Originally by MuleSoft.
Other
249 stars 203 forks source link

Could not find job with key ... #31

Closed ldewailly closed 11 years ago

ldewailly commented 11 years ago

Hi,

I've been testing replacing Quartz DB clustering with yours and I am running into an issue when the scheduler starts:

org.quartz.JobPersistenceException: Could not find job with key DEFAULT.FeedLoader
    at com.novemberain.quartz.mongodb.MongoDBJobStore.storeTrigger(MongoDBJobStore.java:194) ~[quartz-mongodb-1.3.0-beta1.jar:na]
    at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:886) ~[quartz-2.1.7.jar:na]
    at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:259) ~[quartz-2.1.7.jar:na]
    at org.springframework.scheduling.quartz.SchedulerAccessor.addTriggerToScheduler(SchedulerAccessor.java:371) ~[spring-context-support-3.2.3.RELEASE.jar:3.2.3.RELEASE]

Note that I am using the following:

Here is a extract from my Spring wiring:

<bean id="feedLoaderTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail">
            <bean class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
                <property name="name" value="FeedLoader" />
                <property name="jobClass" value="..my job class..." />
                <property name="durability" value="true" />
            </bean>
        </property>
        <property name="cronExpression" value="...my cron expression..." />
    </bean>
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="schedulerName" value="ClusteredScheduler" />
        <property name="triggers">
            <list>
                <ref bean="feedLoaderTrigger"/>
            </list>
        </property>
        <property name="applicationContextSchedulerContextKey">
            <value>applicationContext</value>
        </property>
        <property name="quartzProperties">
            <props>
                <prop key="org.quartz.scheduler.instanceName">ClusteredScheduler</prop>
                <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
                <prop key="org.quartz.threadPool.threadCount">4</prop>

                <prop key="org.quartz.jobStore.class">com.novemberain.quartz.mongodb.MongoDBJobStore</prop>
                <prop key="org.quartz.jobStore.addresses">...</prop>
                <prop key="org.quartz.jobStore.username">...</prop>
                <prop key="org.quartz.jobStore.password">...</prop>
                <prop key="org.quartz.jobStore.dbName">quartz</prop>
            </props>
        </property>
    </bean>

MongoDBJobStore.storeJobInMongo is invoked but it is invoked with replaceExisting set to true. Which causes an update on a non existing record. The flag is set to true in the Spring code ( org.springframework.scheduling.quartz.addJobToScheduler ). That said I think storeJobInMongo() should be creating the record regardless of replaceExisting if it doesn't exist.

What do you think? Happy to contribute a fix you think it makes sense.

Thanks, Ludovic

michaelklishin commented 11 years ago

This store does not implement clustering support. I'm not sure why the Spring method may be using replaceExisting but it's wrong.

Making storeJobInMongo create a new document even if replaceExisting is true would simply hiding the actual issue.

ldewailly commented 11 years ago

Okay, thanks for taking a look. I didn't realise clustering was not supported!

On a side note the JDBC implementation of JobStore.storeJob does exhibit the behaviour I described above (inserting instead of updating if the job does not exist regardless of the value of replaceExisting).

michaelklishin commented 11 years ago

Ok, then I'd accept a pull request that makes the change.