-
Notifications
You must be signed in to change notification settings - Fork 8
/
workflow.clj
57 lines (48 loc) · 1.76 KB
/
workflow.clj
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
;; Copyright © 2022 Manetu, Inc. All rights reserved
(ns temporal.workflow
"Methods for defining and implementing Temporal workflows"
(:require [taoensso.timbre :as log]
[temporal.internal.utils :as u]
[temporal.internal.workflow :as w])
(:import [io.temporal.workflow Workflow]
[java.util.function Supplier]))
(defn get-info
"Return info about the current workflow"
[]
(w/get-info))
(defn- ->supplier
[f]
(reify Supplier
(get [_]
(f))))
(defn await
"Efficiently parks the workflow until 'pred' evaluates to true. Re-evaluates on each state transition"
([pred]
(Workflow/await (->supplier pred)))
([duration pred]
(Workflow/await duration (->supplier pred))))
(defmacro defworkflow
"
Defines a new workflow, similar to defn, expecting a 2-arity parameter list and body. Should evaluate to something
serializable, which will become available for [[temporal.client.core/get-result]].
Arguments:
- `ctx`: Context passed through from [[temporal.client.worker/start]]
- `params`: A map containing the following
- `args`: Passed from 'params' to [[temporal.client.core/start]] or [[temporal.client.core/signal-with-start]]
- `signals`: Signal context for use with signal calls such as [[temporal.signals/<!]] and [[temporal.signals/poll]]
```clojure
(defworkflow my-workflow
[ctx {{:keys [foo]} :args}]
...)
(let [w (create-workflow client my-workflow {:task-queue ::my-task-queue})]
(start w {:foo \"bar\"}))
```
"
[name params* & body]
(let [fqn (u/get-fq-classname name)
sname (str name)]
`(def ~name ^{::w/def {:name ~sname :fqn ~fqn}}
(fn [ctx# args#]
(log/trace (str ~fqn ": ") args#)
(let [f# (fn ~params* (do ~@body))]
(f# ctx# args#))))))