11(ns cronut.integration-test
22 (:require [clojure.core.async :as async]
3- [clojure.java.io :as io]
43 [clojure.tools.logging :as log]
5- [cronut.integrant :as cig ]
6- [integrant.core :as ig ])
4+ [cronut :as cronut ]
5+ [cronut.trigger :as trigger ])
76 (:import (java.util UUID)
87 (org.quartz Job)))
98
1211 (execute [this _job-context]
1312 (log/info " Defrecord Impl:" this)))
1413
15- (defmethod ig /init-key :dep/one
16- [_ config]
17- config )
18-
19- (defmethod ig /init-key :test.job/one
20- [_ config]
21- (reify Job
22- (execute [_this _job-context]
23- (log/info " Reified Impl:" config))))
24-
25- (defmethod ig /init-key :test.job/two
26- [_ config]
27- (map->TestDefrecordJobImpl config))
28-
29- (defmethod ig /init-key :test.job/three
30- [_ config]
31- (reify Job
32- (execute [_this _job-context]
33- (let [rand-id (str (UUID/randomUUID ))]
34- (log/info rand-id " Reified Impl (Job Delay 7s):" config)
35- (async/<!! (async/timeout 7000 ))
36- (log/info rand-id " Finished" )))))
37-
38- (defn init-system
39- " Convenience for starting integrant systems with cronut data-readers"
40- ([]
41- (init-system (slurp (io/resource " config.edn" ))))
42- ([config]
43- (init-system config nil ))
44- ([config readers]
45- (ig/init (ig/read-string {:readers (merge cig/data-readers readers)} config))))
14+ (def reify-job (reify Job
15+ (execute [_this _job-context]
16+ (let [rand-id (str (UUID/randomUUID ))]
17+ (log/info rand-id " Reified Impl (Job Delay 7s)" )
18+ (async/<!! (async/timeout 7000 ))
19+ (log/info rand-id " Finished" )))))
20+
21+ ; (do (require '[cronut.integration-test :as it])
22+ ; (it/test-system))
23+ (defn test-system
24+ []
25+ (let [scheduler (cronut/scheduler {:concurrent-execution-disallowed? true })]
26+ (cronut/clear scheduler)
27+
28+ (async/<!! (async/timeout 2000 ))
29+
30+ (log/info " scheduling defrecord job on 1s interval" )
31+ (cronut/schedule-job scheduler
32+ (trigger/interval 1000 )
33+ (map->TestDefrecordJobImpl {:identity [" test-group" " test-name" ]
34+ :description " test job"
35+ :recover? true
36+ :durable? false }))
37+
38+ ; ; demonstrate scheduler can start with jobs, and jobs can start after scheduler
39+ (cronut/start scheduler)
40+
41+ (async/<!! (async/timeout 2000 ))
42+
43+ ; ; demonstrates concurrency disallowed (every second job runs, 10s interval between jobs that should run every 5s)
44+ (log/info " scheduling reify/7s/no-misfire job on 5s interval" )
45+ (cronut/schedule-job scheduler
46+ (trigger/builder {:type :cron
47+ :cron " */5 * * * * ?"
48+ :misfire :do-nothing })
49+ reify-job)
50+
51+ (async/<!! (async/timeout 15000 ))
52+
53+
54+ (log/info " deleting job test-group/test-name" )
55+ (cronut/delete-job scheduler " test-name" " test-group" )
56+
57+ (async/<!! (async/timeout 15000 ))
58+
59+ (cronut/shutdown scheduler)))
0 commit comments