Created
February 19, 2016 12:10
-
-
Save ashishnegi/d3239a8b65b6dc185402 to your computer and use it in GitHub Desktop.
My problem with quartz.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thanks for quartzite. | |
I am trying to make quartz work with jdbc store. However, i find that new jobs are not triggering. | |
I can see all new jobs and triggers in my database. My `defjobs` from another files also work. | |
It is just that jobs are not getting triggered. | |
My scheduler code is : | |
```clj | |
(ns theophrastus.utils | |
(:require [clojurewerkz.quartzite.scheduler :as qsched] | |
[clojurewerkz.quartzite.triggers :as qtrigger] | |
[clojurewerkz.quartzite.jobs :as qjobs] | |
[clojurewerkz.quartzite.jobs :refer [defjob]] | |
[clojurewerkz.quartzite.schedule.simple :refer [schedule with-repeat-count with-interval-in-milliseconds]] | |
[theophrastus.tasks :as ttasks] | |
[clj-time.core :as tt]) | |
(:import [theophrastus.tasks NoOpJob]) | |
(:import theophrastus.listeners) | |
(:import java.util.UUID) | |
(:import java.lang.Thread)) | |
(qtrigger/key "triggers.102") | |
(qjobs/key "jobs.102") | |
(def scheduler (atom nil)) | |
(defjob NoOpJob-in-file | |
[ctx] | |
(println "Running no-op-job")) | |
(defn start-scheduler [] | |
(let [s (-> (qsched/initialize) qsched/start) | |
x (println (.getMetaData s)) | |
job (qjobs/build | |
(qjobs/of-type NoOpJob-in-file) | |
(qjobs/with-identity (qjobs/key (str (UUID/randomUUID)) "test_job_"))) | |
trigger (qtrigger/build | |
(qtrigger/with-identity (qtrigger/key | |
(str (UUID/randomUUID)) "test_trig_")) | |
(qtrigger/start-at (-> 5 tt/seconds tt/from-now)) | |
(qtrigger/with-schedule (schedule | |
(with-repeat-count 10) | |
(with-interval-in-milliseconds 200))))] | |
(reset! scheduler s) | |
(qsched/add-scheduler-listener s (listeners.)) | |
(qsched/schedule s job trigger) | |
(println (if (qsched/started? s) | |
">>>>>>>>>> scheduler started : true" | |
">>>>>>>>>> scheduler started : false")) | |
))) | |
``` | |
My properties file is : | |
``` | |
org.quartz.scheduler.threadsInheritContextClassLoaderOfInitializer=true | |
org.quartz.scheduler.classLoadHelper.class=theophrastus.DynamicClassLoadHelper | |
org.quartz.threadPool.threadCount=6 | |
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX | |
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate | |
org.quartz.jobStore.tablePrefix = qrtz_ | |
org.quartz.jobStore.dataSource = ashish | |
org.quartz.dataSource.ashish.driver=org.postgresql.Driver | |
org.quartz.dataSource.ashish.URL=jdbc:postgresql://localhost:5438/french_castle | |
org.quartz.dataSource.ashish.user=french_castle | |
org.quartz.dataSource.ashish.password=castle | |
``` | |
I added scheduler listener with below code to get scheduler state messages : | |
```clj | |
(ns theophrastus.listeners | |
(:gen-class :extends org.quartz.listeners.SchedulerListenerSupport | |
:expose-methods {-jobAdded jobAdded | |
-jobScheduled jobScheduled | |
-schedulerError schedulerError | |
-jobDeleted jobDeleted | |
-jobUnscheduled jobUnscheduled | |
-triggerPaused triggerPaused | |
-triggerResumed triggerResumed | |
})) | |
(defn- -jobAdded [this jobDetail] | |
(println ">>>>>>>>>>>>> SchedulerListenerSupport : Job added " + (.getKey jobDetail))) | |
(defn- jobDeleted [this jobDetail] | |
(println ">>>>>>>>>>>>> SchedulerListenerSupport : Job deleted " + (.getKey jobDetail))) | |
(defn- jobUnscheduled [this triggerKey] | |
(println ">>>>>>>>>>>>> SchedulerListenerSupport : Job jobUnscheduled " + triggerKey)) | |
(defn- -jobScheduled [this trigger] | |
(println ">>>>>>>>>>>>> SchedulerListenerSupport : In SchedulerListener jobScheduled with trigger.")) | |
(defn- -schedulerError [this msg exception] | |
(println ">>>>>>>>>>>>> SchedulerListenerSupport : schedulerError : " msg exception)) | |
(defn- triggerPaused [this triggerKey] | |
(println ">>>>>>>>>>>>> SchedulerListenerSupport : Job triggerPaused " + triggerKey)) | |
(defn- triggerResumed [this triggerKey] | |
(println ">>>>>>>>>>>>> SchedulerListenerSupport : Job triggerKey " + triggerKey)) | |
``` | |
The log generated with `lein run server` given to my -main : | |
```log | |
#object[org.quartz.SchedulerMetaData 0x68c7162b Quartz Scheduler (v2.1.7) 'QuartzScheduler' with instanceId 'NON_CLUSTERED' | |
Scheduler class: 'org.quartz.impl.StdScheduler' - running locally. | |
Running since: Fri Feb 19 17:32:51 IST 2016 | |
Not currently in standby mode. | |
Number of jobs executed: 0 | |
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 6 threads. | |
Using job-store 'org.quartz.impl.jdbcjobstore.JobStoreTX' - which supports persistence. and is not clustered. | |
] | |
>>>>>>>>>>>>> SchedulerListenerSupport : Job added #function[clojure.core/+] #object[org.quartz.JobKey 0x2a0c9309 test_job_.fab82dcd-d7b2-45c0-922a-96bc4d5c2444] | |
>>>>>>>>>>>>> SchedulerListenerSupport : In SchedulerListener jobScheduled with trigger. | |
>>>>>>>>>> scheduler started : true | |
``` | |
However, when i comment out my datasource and jobstore from quartz.properties, | |
i get in logs : | |
```log | |
#object[org.quartz.SchedulerMetaData 0x23338420 Quartz Scheduler (v2.1.7) 'QuartzScheduler' with instanceId 'NON_CLUSTERED' | |
Scheduler class: 'org.quartz.impl.StdScheduler' - running locally. | |
Running since: Fri Feb 19 17:34:14 IST 2016 | |
Not currently in standby mode. | |
Number of jobs executed: 0 | |
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 6 threads. | |
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered. | |
] | |
>>>>>>>>>>>>> SchedulerListenerSupport : Job added #function[clojure.core/+] #object[org.quartz.JobKey 0x7e18b9e6 test_job_.ef2e0407-8cb8-468e-9350-105ff7291553] | |
>>>>>>>>>>>>> SchedulerListenerSupport : In SchedulerListener jobScheduled with trigger. | |
>>>>>>>>>> scheduler started : true | |
2016-02-19 17:34:14.458 INFO [main] theophrastus.core - Server up and running! | |
Running no-op-job | |
Running no-op-job | |
Running no-op-job | |
Running no-op-job | |
Running no-op-job | |
Running no-op-job | |
Running no-op-job | |
Running no-op-job | |
Running no-op-job | |
Running no-op-job | |
Running no-op-job | |
``` | |
What i am doing wrong with Persistent stores ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added more logging in my listener and that pointed out that "sched_time" is null and should not be null for the database and throwing exceptions which lead to job not running.
I found that my quartz version : 2.1.7 but used other version pgsql statements during initial creation of qrtz_* tables.
using 2.1.7 pgsql statements solved the problem.