-
Notifications
You must be signed in to change notification settings - Fork 8
/
workflow.clj
44 lines (37 loc) · 1.36 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
;; Copyright © 2022 Manetu, Inc. All rights reserved
(ns temporal.workflow
"Methods for defining Temporal workflows"
(:require [taoensso.timbre :as log]
[temporal.internal.utils :as u]
[temporal.internal.workflow :as w]))
(defn get-info
"
Return info about the current workflow
"
[]
(w/get-info))
(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#))))))