-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.clj
More file actions
65 lines (53 loc) · 2.33 KB
/
integration_test.clj
File metadata and controls
65 lines (53 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(ns cronut.integration-test
(:require [clojure.core.async :as async]
[clojure.tools.logging :as log]
[cronut :as cronut]
[cronut.trigger :as trigger])
(:import (java.util UUID)
(org.quartz Job)))
(defrecord TestDefrecordJobImpl []
Job
(execute [this _job-context]
(log/info "Defrecord Impl:" this)))
(def reify-job (reify Job
(execute [_this _job-context]
(let [rand-id (str (UUID/randomUUID))]
(log/info rand-id "Reified Impl (Job Delay 7s)")
(async/<!! (async/timeout 7000))
(log/info rand-id "Finished")))))
;(do (require '[cronut.integration-test :as it])
; (it/test-system))
(defn test-system
[]
(let [scheduler (cronut/scheduler {:concurrent-execution-disallowed? true})]
(cronut/clear scheduler)
(async/<!! (async/timeout 2000))
(log/info "scheduling defrecord job on 1s interval")
(cronut/schedule-job scheduler
(trigger/interval 1000)
(map->TestDefrecordJobImpl {})
{:name "name1"
:group "group2"
:description "test job"
:recover? true
:durable? false})
;; demonstrate scheduler can start with jobs, and jobs can start after scheduler
(cronut/start scheduler)
(async/<!! (async/timeout 2000))
;; demonstrates concurrency disallowed (every second job runs, 10s interval between jobs that should run every 5s)
(log/info "scheduling reify/7s/no-misfire job on 5s interval")
(cronut/schedule-job scheduler
(trigger/builder {:type :cron
:cron "*/5 * * * * ?"
:misfire :do-nothing})
reify-job
{:name "name2"
:group "group2"
:description "test job 2"
:recover? false
:durable? true})
(async/<!! (async/timeout 15000))
(log/info "deleting job group2.name1")
(cronut/delete-job scheduler "name1" "group2")
(async/<!! (async/timeout 15000))
(cronut/shutdown scheduler)))