Liking cljdoc? Tell your friends :D

temporal.activity

Methods for defining and invoking activity tasks

Methods for defining and invoking activity tasks
raw docstring

defactivitycljmacro

(defactivity name params* & body)

Defines a new activity, similar to defn, expecting a 2-arity parameter list and body. Should evaluate to something serializable, which will be available to the invoke caller, or to a core.async channel (See Async Mode below).

Async Mode:

Returning a core.async channel places the activity into Asynchronous mode, where the result may be resolved at a future time by sending a single message on the channel. Sending a Throwable will signal a failure of the activity. Any other value will be serialized and returned to the caller.

Arguments:

(defactivity greet-activity
    [ctx {:keys [name] :as args}]
    (str "Hi, " name))
Defines a new activity, similar to defn, expecting a 2-arity parameter list and body.  Should evaluate to something
serializable, which will be available to the [[invoke]] caller, or to a core.async channel (See Async Mode below).

#### Async Mode:
Returning a core.async channel places the activity into
[Asynchronous](https://docs.temporal.io/java/activities/#asynchronous-activity-completion) mode, where the result may
be resolved at a future time by sending a single message on the channel.  Sending a
[Throwable](https://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html) will signal a failure of the activity.
Any other value will be serialized and returned to the caller.

Arguments:

- `ctx`: Context passed through from [[temporal.client.worker/start]]
- `args`: Passed from 'params' of [[invoke]]

```clojure
(defactivity greet-activity
    [ctx {:keys [name] :as args}]
    (str "Hi, " name))
```
sourceraw docstring

invokeclj

(invoke activity params)
(invoke activity params options)

Invokes 'activity' with 'params' from within a workflow context. Returns a promise that when derefed will resolve to the evaluation of the defactivity once the activity concludes.

Arguments:

  • activity: A reference to a symbol registered with defactivity.
  • params: Opaque serializable data that will be passed as arguments to the invoked activity
  • options: See below.

options map

ValueDescriptionTypeDefault
:cancellation-typeDefines the activity's stub cancellation mode.See cancellation types below:try-cancel
:heartbeat-timeoutHeartbeat interval.Duration
:retry-optionsDefine how activity is retried in case of failure.temporal.common/retry-options
:start-to-close-timeoutMaximum time of a single Activity execution attempt.Duration3 seconds
:schedule-to-close-timeoutTotal time that a workflow is willing to wait for Activity to complete.Duration
:schedule-to-start-timeoutTime that the Activity Task can stay in the Task Queue before it is picked up by a Worker.Duration

cancellation types

ValueDescription
:try-cancelIn case of activity's scope cancellation send an Activity cancellation request to the server, and report cancellation to the Workflow Execution by causing the activity stub call to fail with CancelledFailure
:abandonDo not request cancellation of the Activity Execution at all (no request is sent to the server) and immediately report cancellation to the Workflow Execution by causing the activity stub call to fail with CancelledFailure immediately.
:wait-cancellation-completedWait for the Activity Execution to confirm any requested cancellation.
(defactivity my-activity
   [ctx {:keys [foo] :as args}]
   ...)

(invoke my-activity {:foo "bar"} {:start-to-close-timeout (Duration/ofSeconds 3))
Invokes 'activity' with 'params' from within a workflow context.  Returns a promise that when derefed will resolve to
the evaluation of the defactivity once the activity concludes.

Arguments:

- `activity`: A reference to a symbol registered with [[defactivity]].
- `params`: Opaque serializable data that will be passed as arguments to the invoked activity
- `options`: See below.

#### options map

| Value                      | Description                                                                                | Type         | Default |
| -------------------------  | ------------------------------------------------------------------------------------------ | ------------ | ------- |
| :cancellation-type         | Defines the activity's stub cancellation mode.                                             | See `cancellation types` below | :try-cancel |
| :heartbeat-timeout         | Heartbeat interval.                                                                        | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | |
| :retry-options             | Define how activity is retried in case of failure.                                         | [[temporal.common/retry-options]] | |
| :start-to-close-timeout    | Maximum time of a single Activity execution attempt.                                       | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | 3 seconds |
| :schedule-to-close-timeout | Total time that a workflow is willing to wait for Activity to complete.                    | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | |
| :schedule-to-start-timeout | Time that the Activity Task can stay in the Task Queue before it is picked up by a Worker. | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | |

#### cancellation types

| Value                        | Description                                                                 |
| -------------------------    | --------------------------------------------------------------------------- |
| :try-cancel                  | In case of activity's scope cancellation send an Activity cancellation request to the server, and report cancellation to the Workflow Execution by causing the activity stub call to fail with [CancelledFailure](https://www.javadoc.io/doc/io.temporal/temporal-sdk/latest/io/temporal/failure/CanceledFailure.html) |
| :abandon                     | Do not request cancellation of the Activity Execution at all (no request is sent to the server) and immediately report cancellation to the Workflow Execution by causing the activity stub call to fail with [CancelledFailure](https://www.javadoc.io/doc/io.temporal/temporal-sdk/latest/io/temporal/failure/CanceledFailure.html) immediately. |
| :wait-cancellation-completed | Wait for the Activity Execution to confirm any requested cancellation.      |

```clojure
(defactivity my-activity
   [ctx {:keys [foo] :as args}]
   ...)

(invoke my-activity {:foo "bar"} {:start-to-close-timeout (Duration/ofSeconds 3))
```
sourceraw docstring

local-invokeclj

(local-invoke activity params)
(local-invoke activity params options)

Invokes 'activity' with 'params' from within a workflow context as a Local Activity. Returns a promise that when derefed will resolve to the evaluation of the defactivity once the activity concludes.

Arguments:

  • activity: A reference to a symbol registered with defactivity.
  • params: Opaque serializable data that will be passed as arguments to the invoked activity
  • options: See below.

options map

ValueDescriptionTypeDefault
:start-to-close-timeoutMaximum time of a single Activity execution attempt.Duration
:schedule-to-close-timeoutTotal time that a workflow is willing to wait for Activity to complete.Duration
:retry-optionsDefine how activity is retried in case of failure.temporal.common/retry-options
:do-not-include-argsWhen set to true, the serialized arguments of the local Activity are not included in the Marker Event that stores the local Activity's invocation result.booleanfalse
:local-retry-thresholdMaximum time to retry locally, while keeping the Workflow Task open via a Heartbeat.Duration
(defactivity my-activity
   [ctx {:keys [foo] :as args}]
   ...)

(local-invoke my-activity {:foo "bar"} {:start-to-close-timeout (Duration/ofSeconds 3))
Invokes 'activity' with 'params' from within a workflow context as a [Local Activity](https://docs.temporal.io/concepts/what-is-a-local-activity/).  Returns a promise that when
derefed will resolve to the evaluation of the defactivity once the activity concludes.

Arguments:

- `activity`: A reference to a symbol registered with [[defactivity]].
- `params`: Opaque serializable data that will be passed as arguments to the invoked activity
- `options`: See below.

#### options map

| Value                      | Description                                                                                | Type         | Default |
| -------------------------  | ------------------------------------------------------------------------------------------ | ------------ | ------- |
| :start-to-close-timeout    | Maximum time of a single Activity execution attempt.                                       | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | |
| :schedule-to-close-timeout | Total time that a workflow is willing to wait for Activity to complete.                    | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | |
| :retry-options             | Define how activity is retried in case of failure.                                         | [[temporal.common/retry-options]] | |
| :do-not-include-args       | When set to true, the serialized arguments of the local Activity are not included in the Marker Event that stores the local Activity's invocation result. | boolean | false |
| :local-retry-threshold     | Maximum time to retry locally, while keeping the Workflow Task open via a Heartbeat.       | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | |

```clojure
(defactivity my-activity
   [ctx {:keys [foo] :as args}]
   ...)

(local-invoke my-activity {:foo "bar"} {:start-to-close-timeout (Duration/ofSeconds 3))
```
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close