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).
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.
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.
Quartz does not create the necessary tables in database automatically, you need to create them while application startup.
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.
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");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With