Methods for defining and implementing Temporal workflows
Methods for defining and implementing Temporal workflows
(await pred)(await duration pred)Efficiently parks the workflow until 'pred' evaluates to true. Re-evaluates on each state transition
Efficiently parks the workflow until 'pred' evaluates to true. Re-evaluates on each state transition
(defworkflow name params* & body)Defines a new workflow, similar to defn, expecting a 1-arity parameter list and body. Should evaluate to something
serializable, which will become available for temporal.client.core/get-result.
Arguments:
args: Passed from 'params' to temporal.client.core/start or temporal.client.core/signal-with-start(defworkflow my-workflow
[{:keys [foo]}]
...)
(let [w (create-workflow client my-workflow {:task-queue ::my-task-queue})]
(start w {:foo "bar"}))
Defines a new workflow, similar to defn, expecting a 1-arity parameter list and body. Should evaluate to something
serializable, which will become available for [[temporal.client.core/get-result]].
Arguments:
- `args`: Passed from 'params' to [[temporal.client.core/start]] or [[temporal.client.core/signal-with-start]]
```clojure
(defworkflow my-workflow
[{:keys [foo]}]
...)
(let [w (create-workflow client my-workflow {:task-queue ::my-task-queue})]
(start w {:foo "bar"}))
```(get-info)Return info about the current workflow
Return info about the current workflow
(get-version change-id min max)Used to safely perform backwards incompatible changes to workflow definitions
Used to safely perform backwards incompatible changes to workflow definitions
(invoke workflow params)(invoke workflow params options)Invokes a 'child workflow' with 'params' from within a workflow context. Returns a promise that when derefed will resolve to the evaluation of the defworkflow once the workflow concludes.
Arguments:
workflow: A reference to a symbol registered with defworkflow, called a Child Workflow usually.params: Opaque serializable data that will be passed as arguments to the invoked child workflowoptions: See below.| Value | Description | Type | Default |
|---|---|---|---|
| :task-queue | Task queue to use for child workflow tasks | String | |
| :workflow-id | Workflow id to use when starting | String | |
| :workflow-id-reuse-policy | Specifies server behavior if a completed workflow with the same id exists | See workflow id reuse policy types below | |
| :parent-close-policy | Specifies how this workflow reacts to the death of the parent workflow | See parent close policy types below | |
| :workflow-execution-timeout | The time after which child workflow execution is automatically terminated | Duration | 10 seconds |
| :workflow-run-timeout | The time after which child workflow run is automatically terminated | Duration | |
| :workflow-task-timeout | Maximum execution time of a single workflow task | Duration | |
| :retry-options | RetryOptions that define how child workflow is retried in case of failure | temporal.common/retry-options | |
| :cron-schedule | A cron schedule string | String | |
| :cancellation-type | In case of a child workflow cancellation it fails with a CanceledFailure | See cancellation types below | |
| :memo | Specifies additional non-indexed information in result of list workflow | String |
| Value | Description |
|---|---|
| :try-cancel | Initiate a cancellation request and immediately report cancellation to the parent |
| :abandon | Do not request cancellation of the child workflow |
| :wait-cancellation-completed | Wait for child cancellation completion |
| :wait-cancellation-requested | Request cancellation of the child and wait for confirmation that the request was received |
| Value | Description |
|---|---|
| :abandon | Do not request cancellation of the child workflow |
| :request-cancel | Request cancellation of the child and wait for confirmation that the request was received |
| :terminate | Terminate the child workflow |
| Value | Description |
|---|---|
| :allow-duplicate | Allow starting a child workflow execution using the same workflow id. |
| :allow-duplicate-failed-only | Allow starting a child workflow execution using the same workflow id, only when the last execution's final state is one of [terminated, cancelled, timed out, failed] |
| :reject-duplicate | Do not permit re-use of the child workflow id for this workflow. |
| :terminate-if-running | If a workflow is running using the same child workflow ID, terminate it and start a new one. If no running child workflow, then the behavior is the same as ALLOW_DUPLICATE |
(defworkflow my-workflow
[ctx {:keys [foo] :as args}]
...)
(invoke my-workflow {:foo "bar"} {:start-to-close-timeout (Duration/ofSeconds 3))
Invokes a 'child workflow' with 'params' from within a workflow context.
Returns a promise that when derefed will resolve to the evaluation of the defworkflow once the workflow concludes.
Arguments:
- `workflow`: A reference to a symbol registered with [[defworkflow]], called a Child Workflow usually.
- `params`: Opaque serializable data that will be passed as arguments to the invoked child workflow
- `options`: See below.
#### options map
| Value | Description | Type | Default |
| --------------------------- | ------------------------------------------------------------------------------------------ | ------------ | ------- |
| :task-queue | Task queue to use for child workflow tasks | String | |
| :workflow-id | Workflow id to use when starting | String | |
| :workflow-id-reuse-policy | Specifies server behavior if a completed workflow with the same id exists | See `workflow id reuse policy types` below | |
| :parent-close-policy | Specifies how this workflow reacts to the death of the parent workflow | See `parent close policy types` below | |
| :workflow-execution-timeout | The time after which child workflow execution is automatically terminated | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | 10 seconds |
| :workflow-run-timeout | The time after which child workflow run is automatically terminated | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | |
| :workflow-task-timeout | Maximum execution time of a single workflow task | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | |
| :retry-options | RetryOptions that define how child workflow is retried in case of failure | [[temporal.common/retry-options]] | |
| :cron-schedule | A cron schedule string | String | |
| :cancellation-type | In case of a child workflow cancellation it fails with a CanceledFailure | See `cancellation types` below | |
| :memo | Specifies additional non-indexed information in result of list workflow | String | |
#### cancellation types
| Value | Description |
| ------------------------- | --------------------------------------------------------------------------- |
| :try-cancel | Initiate a cancellation request and immediately report cancellation to the parent |
| :abandon | Do not request cancellation of the child workflow |
| :wait-cancellation-completed | Wait for child cancellation completion |
| :wait-cancellation-requested | Request cancellation of the child and wait for confirmation that the request was received |
#### parent close policy types
| Value | Description |
| ------------------------- | --------------------------------------------------------------------------- |
| :abandon | Do not request cancellation of the child workflow |
| :request-cancel | Request cancellation of the child and wait for confirmation that the request was received |
| :terminate | Terminate the child workflow |
#### workflow id reuse policy types
| Value | Description |
| ---------------------------- | --------------------------------------------------------------------------- |
| :allow-duplicate | Allow starting a child workflow execution using the same workflow id. |
| :allow-duplicate-failed-only | Allow starting a child workflow execution using the same workflow id, only when the last execution's final state is one of [terminated, cancelled, timed out, failed] |
| :reject-duplicate | Do not permit re-use of the child workflow id for this workflow. |
| :terminate-if-running | If a workflow is running using the same child workflow ID, terminate it and start a new one. If no running child workflow, then the behavior is the same as ALLOW_DUPLICATE |
```clojure
(defworkflow my-workflow
[ctx {:keys [foo] :as args}]
...)
(invoke my-workflow {:foo "bar"} {:start-to-close-timeout (Duration/ofSeconds 3))
```(register-query-handler! f)Registers a DynamicQueryHandler listener that handles queries sent to the workflow, using temporal.client.core/query.
Use inside a workflow definition with 'f' closing over the workflow state (e.g. atom) and evaluating to results in function of the workflow state and its 'query-type' and 'args' arguments.
Arguments:
f: a 2-arity function, expecting 2 arguments, evaluating to something serializable.f arguments:
query-type: keywordargs: params value or data structure(defworkflow stateful-workflow
[{:keys [init] :as args}]
(let [state (atom init)]
(register-query-handler! (fn [query-type args]
(when (= query-type :my-query)
(get-in @state [:path :to :answer]))))
;; workflow implementation
))
Registers a DynamicQueryHandler listener that handles queries sent to the workflow, using [[temporal.client.core/query]].
Use inside a workflow definition with 'f' closing over the workflow state (e.g. atom) and
evaluating to results in function of the workflow state and its 'query-type' and 'args' arguments.
Arguments:
- `f`: a 2-arity function, expecting 2 arguments, evaluating to something serializable.
`f` arguments:
- `query-type`: keyword
- `args`: params value or data structure
```clojure
(defworkflow stateful-workflow
[{:keys [init] :as args}]
(let [state (atom init)]
(register-query-handler! (fn [query-type args]
(when (= query-type :my-query)
(get-in @state [:path :to :answer]))))
;; workflow implementation
))
```(sleep duration)Efficiently parks the workflow for 'duration'
Efficiently parks the workflow for 'duration'
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |