Skip to content

Commit f6b4654

Browse files
committed
prepare for 1.2.0 release
1 parent a2d571c commit f6b4654

File tree

6 files changed

+144
-77
lines changed

6 files changed

+144
-77
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
33

4+
## [1.2.0] - 2025-10-03
5+
6+
- Demonstrate configuration where jobs and opts are separate (as per Cronut 1.2.0)
7+
48
## [1.1.0] - 2025-10-02
59

610
- Breakout cronut-integrant and cronut-javax into separate project repositories

README.md

Lines changed: 106 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
Cronut-Integrant provides bindings for [Cronut](https://github.com/factorhouse/cronut)
99
to [Integrant](https://github.com/weavejester/integrant), the DI micro-framework.
1010

11-
Compatible with either [Cronut](https://github.com/factorhouse/cronut) or [Cronut-Javax](https://github.com/factorhouse/cronut-javax) depending on your requirement of Jakarta or Javax.
11+
Compatible with either [Cronut](https://github.com/factorhouse/cronut)
12+
or [Cronut-Javax](https://github.com/factorhouse/cronut-javax) depending on your requirement of Jakarta or Javax.
1213

1314
## Related Projects
1415

1516
| Project | Desription | Clojars Project |
1617
|-------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
17-
| [cronut](https://github.com/factorhouse/cronut) | Cronut with [Jakarta](https://en.wikipedia.org/wiki/Jakarta_EE) support (Primary) | [![Clojars Project](https://img.shields.io/clojars/v/io.factorhouse/cronut.svg)](https://clojars.org/io.factorhouse/cronut) |
18+
| [cronut](https://github.com/factorhouse/cronut) | Cronut with [Jakarta](https://en.wikipedia.org/wiki/Jakarta_EE) support (Primary) | [![Clojars Project](https://img.shields.io/clojars/v/io.factorhouse/cronut.svg)](https://clojars.org/io.factorhouse/cronut) |
1819
| [cronut-javax](https://github.com/factorhouse/cronut-javax) | Cronut with [Javax](https://jakarta.ee/blogs/javax-jakartaee-namespace-ecosystem-progress/) support (Legacy) | [![Clojars Project](https://img.shields.io/clojars/v/io.factorhouse/cronut-javax.svg)](https://clojars.org/io.factorhouse/cronut-javax) |
1920

2021
# Contents
@@ -48,25 +49,44 @@ Compatible with either [Cronut](https://github.com/factorhouse/cronut) or [Cronu
4849

4950
A quartz `scheduler` runs a `job` on a schedule defined by a `trigger`.
5051

52+
A `job` or `trigger` is uniquely identified by a `key` consisting of a `name` and (optional) `group`.
53+
54+
A `job` can have multiple `triggers`, a `trigger` is for a single `job` only.
55+
5156
## `:cronut/scheduler` definition
5257

5358
Cronut provides access to the Quartz Scheduler, exposed via Integrant with `:cronut/scheduler`
5459

5560
The scheduler supports the following fields:
5661

57-
1. `:schedule`: (required) - a sequence of 'items' to schedule, each being a map containing a :job and :trigger
62+
1. `:schedule`: (required) - a sequence of 'items' to schedule, each being a map containing a :job:, :opts, and :trigger
5863
2. `:concurrent-execution-disallowed?`: (optional, default false) - run all jobs with @DisableConcurrentExecution
5964
3. `:update-check?`: (optional, default false) - check for Quartz updates on system startup
6065

6166
### Scheduler example
6267

6368
````clojure
64-
:cronut/scheduler {:schedule [{:job #ig/ref :test.job/two
65-
:trigger #cronut/interval 3500}
66-
{:job #ig/ref :test.job/two
67-
:trigger #cronut/cron "*/8 * * * * ?"
68-
:misfire :do-nothing}]
69-
:concurrent-execution-disallowed? true}
69+
:cronut/scheduler {:update-check? false
70+
:concurrent-execution-disallowed? true
71+
:schedule [;; basic interval
72+
{:job #ig/ref :test.job/one
73+
:opts {:description "test job 1, identity auto-generated"}
74+
:trigger #cronut/trigger {:type :simple
75+
:interval 2
76+
:time-unit :seconds
77+
:repeat :forever}}
78+
79+
;; full interval
80+
{:job #ig/ref :job/two
81+
:opts #ig/ref :job/two-opts
82+
:trigger #cronut/trigger {:type :simple
83+
:interval 3000
84+
:repeat :forever
85+
:identity ["trigger-two" "test"]
86+
:description "test trigger"
87+
:start #inst "2019-01-01T00:00:00.000-00:00"
88+
:end #inst "2019-02-01T00:00:00.000-00:00"
89+
:priority 5}}
7090
````
7191

7292
## `:job` definition
@@ -93,22 +113,45 @@ or by returning a `defrecord` that implements the interface. e.g.
93113
(map->TestDefrecordJobImpl config))
94114
````
95115

96-
Cronut supports further Quartz configuration of jobs (identity, description, recovery, and durability) by expecting
97-
those values to be assoc'd onto your job. You do not have to set them (in fact in most cases you can likely ignore
98-
them), however if you do want that control you will likely use the `defrecord` approach as opposed to `reify`.
116+
Cronut supports further Quartz configuration of jobs (identity, description, recovery, and durability) by configuring an
117+
optional `opts` map for each scheduled item.
99118

100-
Concurrent execution can be controlled on a per-job bases with the `disallow-concurrent-execution?` flag.
119+
Concurrent execution can be controlled on a per-job bases with the `disallow-concurrent-execution?` flag in `opts`.
101120

102121
### Job example
103122

123+
**Job definition**
124+
125+
````clojure
126+
(ns job
127+
(:require [clojure.tools.logging :as log])
128+
(:import (org.quartz Job)))
129+
130+
(defrecord TestDefrecordJobImpl []
131+
Job
132+
(execute [this _job-context]
133+
(log/info "Defrecord Impl:" this)))
134+
135+
;; These two functions are called by Integrant on system startup, see:
136+
;; https://github.com/weavejester/integrant?tab=readme-ov-file#initializer-functions
137+
(defn two
138+
[config]
139+
(map->TestDefrecordJobImpl config))
140+
141+
(def two-opts identity)
142+
````
143+
144+
**Job options**
145+
104146
````clojure
105-
:test.job/two {:identity ["job-two" "test"]
106-
:description "test job"
107-
:recover? true
108-
:durable? false
109-
:disallow-concurrent-execution? true
110-
:dep-one #ig/ref :dep/one
111-
:dep-two #ig/ref :test.job/one}
147+
:job/two {}
148+
:job/two-opts {:name "job2"
149+
:group "group1"
150+
:description "test job 2, identity by name and group"
151+
:recover? true
152+
:durable? false
153+
:dep-one #ig/ref :dep/one
154+
:dep-two #ig/ref :test.job/one}
112155
````
113156

114157
## `:trigger` definition
@@ -212,7 +255,7 @@ e.g.
212255
# Example system
213256

214257
This repository contains an example system composed of of integratant configuration, job definitions, and helper
215-
functions.
258+
functions, see the [test](/test) directory.
216259

217260
## Configuration
218261

@@ -221,28 +264,32 @@ Integrant configuration source: [dev-resources/config.edn](dev-resources/config.
221264
````clojure
222265
{:dep/one {:a 1}
223266

224-
:test.job/one {:dep-one #ig/ref :dep/one}
267+
:job/one {:dep-one #ig/ref :dep/one}
225268

226-
:test.job/two {:identity ["name1" "group2"]
227-
:description "test job"
269+
:job/two {}
270+
:job/two-opts {:name "job2"
271+
:group "group1"
272+
:description "test job 2, identity by name and group"
228273
:recover? true
229274
:durable? false
230275
:dep-one #ig/ref :dep/one
231-
:dep-two #ig/ref :test.job/one}
276+
:dep-two #ig/ref :job/one}
232277

233-
:test.job/three {}
278+
:job/three {}
234279

235280
:cronut/scheduler {:update-check? false
236281
:concurrent-execution-disallowed? true
237282
:schedule [;; basic interval
238-
{:job #ig/ref :test.job/one
283+
{:job #ig/ref :job/one
284+
:opts {:description "test job 1, identity auto-generated"}
239285
:trigger #cronut/trigger {:type :simple
240286
:interval 2
241287
:time-unit :seconds
242288
:repeat :forever}}
243289

244290
;; full interval
245-
{:job #ig/ref :test.job/two
291+
{:job #ig/ref :job/two
292+
:opts #ig/ref :job/two-opts
246293
:trigger #cronut/trigger {:type :simple
247294
:interval 3000
248295
:repeat :forever
@@ -253,16 +300,19 @@ Integrant configuration source: [dev-resources/config.edn](dev-resources/config.
253300
:priority 5}}
254301

255302
;; shortcut interval
256-
{:job #ig/ref :test.job/two
303+
{:job #ig/ref :job/two
304+
:opts #ig/ref :job/two-opts
257305
:trigger #cronut/interval 3500}
258306

259307
;; basic cron
260-
{:job #ig/ref :test.job/two
308+
{:job #ig/ref :job/two
309+
:opts #ig/ref :job/two-opts
261310
:trigger #cronut/trigger {:type :cron
262311
:cron "*/4 * * * * ?"}}
263312

264313
;; full cron
265-
{:job #ig/ref :test.job/two
314+
{:job #ig/ref :job/two
315+
:opts #ig/ref :job/two-opts
266316
:trigger #cronut/trigger {:type :cron
267317
:cron "*/6 * * * * ?"
268318
:identity ["trigger-five" "test"]
@@ -273,12 +323,15 @@ Integrant configuration source: [dev-resources/config.edn](dev-resources/config.
273323
:priority 4}}
274324

275325
;; shortcut cron
276-
{:job #ig/ref :test.job/two
326+
{:job #ig/ref :job/two
327+
:opts #ig/ref :job/two-opts
277328
:trigger #cronut/cron "*/8 * * * * ?"}
278329

279330
;; Note: This job misfires because it takes 7 seconds to run, but runs every 5 seconds, and isn't allowed to run concurrently with {:disallowConcurrentExecution? true}
280331
;; So every second job fails to run, and is just ignored with the :do-nothing :misfire rule
281-
{:job #ig/ref :test.job/three
332+
{:job #ig/ref :job/three
333+
:opts {:name "job3"
334+
:description "test job 3, identity by name only - default group"}
282335
:trigger #cronut/trigger {:type :cron
283336
:cron "*/5 * * * * ?"
284337
:misfire :do-nothing}}]}}
@@ -287,29 +340,40 @@ Integrant configuration source: [dev-resources/config.edn](dev-resources/config.
287340

288341
## Job definitions
289342

290-
Job definitions source: [test/cronut/integration-test.clj](test/cronut/integration_test.clj)
343+
Job definitions source: [test/job.clj](test/job.clj)
291344

292345
```clojure
293-
(defrecord TestDefrecordJobImpl [identity description recover? durable? test-dep disallow-concurrent-execution?]
294-
Job
295-
(execute [this _job-context]
296-
(log/info "Defrecord Impl:" this)))
346+
(ns job
347+
(:require [clojure.core.async :as async]
348+
[clojure.tools.logging :as log]
349+
[integrant.core :as ig])
350+
(:import (java.util UUID)
351+
(org.quartz Job)))
297352

298353
(defmethod ig/init-key :dep/one
299354
[_ config]
300355
config)
301356

302-
(defmethod ig/init-key :test.job/one
357+
(defmethod ig/init-key ::one
303358
[_ config]
304359
(reify Job
305360
(execute [_this _job-context]
306361
(log/info "Reified Impl:" config))))
307362

308-
(defmethod ig/init-key :test.job/two
309-
[_ config]
363+
(defrecord TestDefrecordJobImpl []
364+
Job
365+
(execute [this _job-context]
366+
(log/info "Defrecord Impl:" this)))
367+
368+
;; These next two functions are called by Integrant on system startup, see:
369+
;; https://github.com/weavejester/integrant?tab=readme-ov-file#initializer-functions
370+
(defn two
371+
[config]
310372
(map->TestDefrecordJobImpl config))
311373

312-
(defmethod ig/init-key :test.job/three
374+
(def two-opts identity)
375+
376+
(defmethod ig/init-key ::three
313377
[_ config]
314378
(reify Job
315379
(execute [_this _job-context]

dev-resources/config.edn

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{:dep/one {:a 1}
22

3-
:test.job/one {:dep-one #ig/ref :dep/one}
3+
:job/one {:dep-one #ig/ref :dep/one}
44

55
:job/two {}
66
:job/two-opts {:name "job2"
@@ -9,14 +9,14 @@
99
:recover? true
1010
:durable? false
1111
:dep-one #ig/ref :dep/one
12-
:dep-two #ig/ref :test.job/one}
12+
:dep-two #ig/ref :job/one}
1313

14-
:test.job/three {}
14+
:job/three {}
1515

1616
:cronut/scheduler {:update-check? false
1717
:concurrent-execution-disallowed? true
1818
:schedule [;; basic interval
19-
{:job #ig/ref :test.job/one
19+
{:job #ig/ref :job/one
2020
:opts {:description "test job 1, identity auto-generated"}
2121
:trigger #cronut/trigger {:type :simple
2222
:interval 2
@@ -65,7 +65,7 @@
6565

6666
;; Note: This job misfires because it takes 7 seconds to run, but runs every 5 seconds, and isn't allowed to run concurrently with {:disallowConcurrentExecution? true}
6767
;; So every second job fails to run, and is just ignored with the :do-nothing :misfire rule
68-
{:job #ig/ref :test.job/three
68+
{:job #ig/ref :job/three
6969
:opts {:name "job3"
7070
:description "test job 3, identity by name only - default group"}
7171
:trigger #cronut/trigger {:type :cron

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject io.factorhouse/cronut-integrant "1.1.0"
1+
(defproject io.factorhouse/cronut-integrant "1.2.0"
22

33
:description "Integrant bindings for Cronut"
44

test/cronut/integration_test.clj

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,8 @@
11
(ns cronut.integration-test
2-
(:require [clojure.core.async :as async]
3-
[clojure.java.io :as io]
4-
[clojure.tools.logging :as log]
2+
(:require [clojure.java.io :as io]
53
[cronut.integrant :as cig]
64
[integrant.core :as ig]
7-
[job])
8-
(:import (java.util UUID)
9-
(org.quartz Job)))
10-
11-
(defmethod ig/init-key :dep/one
12-
[_ config]
13-
config)
14-
15-
(defmethod ig/init-key :test.job/one
16-
[_ config]
17-
(reify Job
18-
(execute [_this _job-context]
19-
(log/info "Reified Impl:" config))))
20-
21-
(defmethod ig/init-key :test.job/three
22-
[_ config]
23-
(reify Job
24-
(execute [_this _job-context]
25-
(let [rand-id (str (UUID/randomUUID))]
26-
(log/info rand-id "Reified Impl (Job Delay 7s):" config)
27-
(async/<!! (async/timeout 7000))
28-
(log/info rand-id "Finished")))))
5+
[job]))
296

307
(defn init-system
318
"Example of starting integrant cronut systems with data-readers"

0 commit comments

Comments
 (0)