Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making Quartz scheduler persistent without JDBC

We're building an app around MongoDB, and have a need to run cron-like jobs periodically. I've used Quartz before for this kind of thing when projects were based around an RDBMS with JDBC.

Since we're already using MongoDB for our main datastore in this project, I'd prefer to not introduce an RDBMS simply to persist Quartz jobs, but there doesn't seem to be any kind of JobStore implementatiom for MongoDB.

Can anyone recommend either a way to back Quartz with MongoDB, or a simple alternative to Quartz? My needs are fairly simple (run various java jobs with some manner of configuration, à la cron).

like image 328
George Armhold Avatar asked Jan 25 '11 20:01

George Armhold


People also ask

Does Quartz require database?

To use JDBCJobStore, you must first create a set of database tables for Quartz to use. You can find table-creation SQL scripts in the “docs/dbTables” directory of the Quartz distribution.

How does Quartz Scheduler work internally?

Quartz scheduler allows an enterprise to schedule a job at a specified date and time. It allows us to perform the operations to schedule or unschedule the jobs. It provides operations to start or stop or pause the scheduler. It also provides reminder services.

Does Quartz create tables automatically?

Quartz does not create the necessary tables in database automatically, you need to create them while application startup.


2 Answers

Edit: Latest implementation https://github.com/michaelklishin/quartz-mongodb forked from below repo


I wrote a MongoDB JobStore for Quartz which is located here: https://github.com/mulesoft/quartz-mongodb It doesn't support everything, but it works for a bunch of use cases.

like image 90
Dan Diephouse Avatar answered Sep 19 '22 00:09

Dan Diephouse


We run quartz with Spring and it's just an XML file with the jobs defined and cron expressions.

Declare a job in Spring:

  <bean name="myJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="concurrent" value="false"/>
    <property name="targetBeanName" value="myBean"/>
    <property name="targetMethod" value="myScheduledMethod"/>
  </bean>

  <bean id="myJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="myJob"/>
    <!-- every 30s -->
    <property name="cronExpression" value="0/30 * * * * ?"/>
  </bean>

Quartz Wiring:

  <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
      <!-- List of batch jobs to be fed to the scheduler. -->
      <list>
        <ref bean="myTrigger"/>
      </list>
    </property>
  </bean>

Run it with:

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App 
{
    public static void main( String[] args ) throws Exception
    {
        new ClassPathXmlApplicationContext("jobs-context.xml");
    }
}
like image 33
Clement P Avatar answered Sep 19 '22 00:09

Clement P