Can't make it work with mongodb backend

449 views
Skip to first unread message

Simone Mosciatti

unread,
Feb 26, 2014, 3:52:19 PM2/26/14
to clojure...@googlegroups.com
Ciao,

I have a very stupid project that use quartz as backend.

I need to have the various job and trigger stored somewhere, and since I know some mongo I decided to use mongo itself.

This is the code:

`
(defn start-quartz []
  (qs/initialize)
  (qs/start))

(j/defjob SimplePrint [ctx]
  (println "Simple"))

(j/defjob MakeRequest [ctx]
  (let [m (conversion/from-job-data ctx)
        method (m "method")
        url (m "url")]
    (println method url)
    (if (= method "get")
      (client/get url)
      (client/post url))))

(defn add-event
  ([end-point method cron]
     (let [[jk tk] [(get-uuid) (get-uuid)]
           job (j/build
                (j/of-type MakeRequest)
                (j/using-job-data {"url" end-point
                                         "method" method})
                (j/with-identity (j/key jk)))
           trigger (t/build
                    (t/with-identity (t/key tk))
                    (t/start-now)
                    (t/with-schedule
                      (schedule
                       (cron-schedule "0/5 * * * * ?"))))]
       (println "Create job: " job)
       (println "Create trigger: " trigger)
       (qs/schedule job trigger)
       [jk tk])))
`

And here are the quartz.properties:

# Use the MongoDB store
org.quartz.jobStore.class=com.novemberain.quartz.mongodb.MongoDBJobStore

# MongoDB URI (optional if 'org.quartz.jobStore.addresses' is set)
org.quartz.jobStore.mongoUri=mongodb://localhost:27017/tick

# comma separated list of mongodb hosts/replica set seeds (optional if 'org.quartz.jobStore.mongoUri' is set)
#org.quartz.jobStore.addresses=host1,host2

# database name
org.quartz.jobStore.dbName=tick

# Will be used to create collections like mycol_jobs, mycol_triggers, mycol_calendars, mycol_locks
org.quartz.jobStore.collectionPrefix=tick

# thread count setting is ignored by the MongoDB store but Quartz requries it
org.quartz.threadPool.threadCount=5


If I don't use this properties and I store everthing in RAM it works just fine, but if I use this properties almost everything breaks.

I say almost because I can actually see that something is working, the next-fire counter in the db is actually growing up, but it just doesn't make any request, nor print anything...

What I am doing wrong ?

Michael Klishin

unread,
Feb 26, 2014, 9:59:10 PM2/26/14
to clojure...@googlegroups.com

2014-02-27 0:52 GMT+04:00 Simone Mosciatti <mweb...@gmail.com>:
if I use this properties almost everything breaks.

Can you be more specific than "breaks"?


--
MK

http://github.com/michaelklishin
http://twitter.com/michaelklishin

Simone Mosciatti

unread,
Feb 27, 2014, 3:43:17 AM2/27/14
to clojure...@googlegroups.com
Let's consider the simple MakeRequest job in the code.

If I don't set the properties and I ask to make a request to localhost with method get every 5 second, every 5 second I receive a get request to localhost, just how it is suppose to be.

If I do set the properties and I run the same job, I don't get any request to localhost, however I can see the counter of the next fire trigger growing up in the mongodb.

Same deal if the job is easier like print something to STDOUT, properties set doesn't work, no properties it works.

I believe I am missing something very basic, but I can't figure out what...

Michael Klishin

unread,
Feb 27, 2014, 4:31:00 AM2/27/14
to clojure...@googlegroups.com

2014-02-27 12:43 GMT+04:00 Simone Mosciatti <mweb...@gmail.com>:
If I do set the properties and I run the same job, I don't get any request to localhost, however I can see the counter of the next fire trigger growing up in the mongodb.

Same deal if the job is easier like print something to STDOUT, properties set doesn't work, no properties it works.

Adding this dependency should help you see Quartz logs in stdout:

Simone Mosciatti

unread,
Feb 27, 2014, 5:03:31 AM2/27/14
to clojure...@googlegroups.com
Humm, maybe I am getting the problem:

2014-02-27 10:54:05 INFO  StdSchedulerFactory:1175 - Using default implementation for ThreadExecutor
2014-02-27 10:54:05 INFO  SchedulerSignalerImpl:61 - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
2014-02-27 10:54:05 INFO  QuartzScheduler:243 - Quartz Scheduler v.2.1.7 created.
2014-02-27 10:54:06 INFO  QuartzScheduler:268 - Scheduler meta-data: Quartz Scheduler (v2.1.7) 'QuartzScheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 5 threads.
  Using job-store 'com.novemberain.quartz.mongodb.MongoDBJobStore' - which supports persistence. and is not clustered.

2014-02-27 10:54:06 INFO  StdSchedulerFactory:1324 - Quartz scheduler 'QuartzScheduler' initialized from default file in current working dir: 'quartz.properties'
2014-02-27 10:54:06 INFO  StdSchedulerFactory:1328 - Quartz scheduler version: 2.1.7
2014-02-27 10:54:06 INFO  QuartzScheduler:534 - Scheduler QuartzScheduler_$_NON_CLUSTERED started.
2014-02-27 10:54:06 ERROR ErrorLogger:2361 - An error occurred while firing triggers '[Trigger 'DEFAULT.7f903fe0-6c61-4647-8b61-95a009bfba05':  triggerClass: 'org.quartz.impl.triggers.CronTriggerImpl calendar: 'null' misfireInstruction: 0 nextFireTime: Thu Feb 27 10:54:06 CET 2014]'
org.quartz.JobPersistenceException: Could not load job class tick.scheduler.MakeRequest [See nested exception: java.lang.ClassNotFoundException: tick.scheduler.MakeRequest]
at com.novemberain.quartz.mongodb.MongoDBJobStore.retrieveJob(MongoDBJobStore.java:205)
at com.novemberain.quartz.mongodb.MongoDBJobStore.retrieveJob(MongoDBJobStore.java:1207)
at com.novemberain.quartz.mongodb.MongoDBJobStore.triggersFired(MongoDBJobStore.java:657)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:326)
Caused by: java.lang.ClassNotFoundException: tick.scheduler.MakeRequest
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.novemberain.quartz.mongodb.MongoDBJobStore.retrieveJob(MongoDBJobStore.java:177)
... 3 more

Basically it says that it can't find the class, let me try to generate the class aot and then import it...

Simone Mosciatti

unread,
Feb 27, 2014, 5:23:02 AM2/27/14
to clojure...@googlegroups.com
Wait, why I am the only one having this problem ? 

Simone Mosciatti

unread,
Feb 27, 2014, 5:38:18 AM2/27/14
to clojure...@googlegroups.com
Ok, it works...

But still, I have generate a class, with (gen-class) compile it aot and then run everything...

Now it runs smooth, but I guess that I am not making things how they should be made...

Am I missing something ?

Michael Klishin

unread,
Feb 27, 2014, 5:56:14 AM2/27/14
to clojure...@googlegroups.com
2014-02-27 14:03 GMT+04:00 Simone Mosciatti <mweb...@gmail.com>:
Basically it says that it can't find the class, let me try to generate the class aot and then import it...

Simone Mosciatti

unread,
Feb 27, 2014, 4:41:42 PM2/27/14
to clojure...@googlegroups.com
Oh, I see...

Thank you.

Anyway in what case is not possible to make MongoDBJobStore load dynamically ?

It is not easier to just define another class in quart-mongodb lib that define a DynamicMongoDBJobStore ?

It would save a lot of time...

Michael Klishin

unread,
Feb 27, 2014, 9:44:07 PM2/27/14
to clojure...@googlegroups.com

2014-02-28 1:41 GMT+04:00 Simone Mosciatti <mweb...@gmail.com>:
It is not easier to just define another class in quart-mongodb lib that define a DynamicMongoDBJobStore ?

And add dependencies on quartz-mongodb and mongodb-java-driver with it? Not everybody uses MongoDB, you know.
Reply all
Reply to author
Forward
0 new messages