You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add register-signal-handler! and signal-channel abstraction
This patch breaks out the signal handling such that the core.async abstraction
surrounding signals is now optional. There is a new function:
temporal.signals/register-signal-handler!
that offers low-level access to the signal callback. The design was inspired
by the work of Thomas Moerman (https://github.com/tmoerman) in the Query support
(See 4f052ae)
This work prompted another cleanup that I had been meaning to do: the removal of the 'ctx'
from the defworkflow. The original design had both defworkflow and defactivity receiving
a user supplied 'ctx', but this never made sense for workflows since the context invites
non-determinism.
So, the new signature of defworkflow is simply a single-arity function that receives the
arguments directly, rather than within a {:keys [signals args]} map. We still support
2-arity clients (for now) with a backwards compatibility check within the macro. This
may be removed in a future release, so we print a WARN to signal the developer of the
deprecation.
Signed-off-by: Greg Haskins <[email protected]>
@@ -155,24 +155,45 @@ Your Workflow may send or receive [signals](https://cljdoc.org/d/io.github.manet
155
155
156
156
#### Receiving Signals
157
157
158
-
Your Workflow may either block waiting with signals with [temporal.signals/<!](https://cljdoc.org/d/io.github.manetu/temporal-sdk/CURRENT/api/temporal.signals#%3C!) or use the non-blocking [temporal.signals/poll](https://cljdoc.org/d/io.github.manetu/temporal-sdk/CURRENT/api/temporal.signals#poll). Either way, your Workflow needs to obtain the `signals` context provided in the Workflow request map.
158
+
##### Channel Abstraction using 'signal-chan'
159
159
160
-
##### Example
160
+
This SDK provides a [core.async](https://github.com/clojure/core.async) inspired abstraction on [Temporal Signals](https://docs.temporal.io/workflows#signal) called signal-channels. To use signal channels, your Workflow may either block waiting with signals with [temporal.signals/<!](https://cljdoc.org/d/io.github.manetu/temporal-sdk/CURRENT/api/temporal.signals#%3C!) or use the non-blocking [temporal.signals/poll](https://cljdoc.org/d/io.github.manetu/temporal-sdk/CURRENT/api/temporal.signals#poll). Either way, your Workflow needs to first obtain the `signal-chan` context obtained by [temporal.signals/create-signal-chan](https://cljdoc.org/d/io.github.manetu/temporal-sdk/CURRENT/api/temporal.signals#create-signal-chan).
161
+
162
+
###### Example
161
163
162
164
```clojure
165
+
(require `[temporal.signals :as s])
166
+
163
167
(defworkflowmy-workflow
164
-
[ctx {:keys [signals]}]
165
-
(let [message (<! signals "MySignal")]
168
+
[args]
169
+
(let [signals (s/create-signal-chan)
170
+
message (<! signals "MySignal")]
166
171
...))
167
172
```
168
173
174
+
##### Raw Signal Handling
175
+
176
+
Alternatively, you may opt to handle signals directly with [temporal.signals/register-signal-handler!](https://cljdoc.org/d/io.github.manetu/temporal-sdk/CURRENT/api/temporal.signals#register-signal-handler!)
Your Workflow may respond to [queries](https://cljdoc.org/d/io.github.manetu/temporal-sdk/CURRENT/api/temporal.client.core#query).
172
193
173
194
A temporal query is similar to a temporal signal, both are messages sent to a running Workflow.
174
195
The difference is that a signal intends to change the behaviour of the Workflow, whereas a query intends to inspect the current state of the Workflow.
175
-
Querying the state of a Workflow implies that the Workflow must maintain state while running, typically in a clojure [atom](https://clojuredocs.org/clojure.core/atom).
196
+
Querying the state of a Workflow implies that the Workflow must maintain state while running, typically in a clojure [atom](https://clojuredocs.org/clojure.core/atom) or [ref](https://clojure.org/reference/refs).
176
197
177
198
#### Registering a Query handler
178
199
@@ -181,7 +202,7 @@ The query handler is a function that has a reference to the Workflow state, usua
0 commit comments