|
1 |
| -;; Copyright © 2022 Manetu, Inc. All rights reserved |
| 1 | +;; Copyright © 2022-2023 Manetu, Inc. All rights reserved |
2 | 2 |
|
3 | 3 | (ns temporal.activity
|
4 | 4 | "Methods for defining and invoking activity tasks"
|
|
8 | 8 | [temporal.internal.activity :as a]
|
9 | 9 | [temporal.internal.utils :as u]
|
10 | 10 | [temporal.internal.promise]) ;; needed for IPromise protocol extention
|
11 |
| - (:import [io.temporal.workflow Workflow])) |
| 11 | + (:import [io.temporal.workflow Workflow] |
| 12 | + [io.temporal.activity Activity])) |
| 13 | + |
| 14 | +(defn heartbeat |
| 15 | + " |
| 16 | +Used to notify the Workflow Execution that the Activity Execution is alive. |
| 17 | +
|
| 18 | +Arguments: |
| 19 | +
|
| 20 | +- `details`: The details are accessible through [[get-heartbeat-details]] on the next Activity Execution retry. |
| 21 | +" |
| 22 | + [details] |
| 23 | + (let [ctx (Activity/getExecutionContext)] |
| 24 | + (log/trace "heartbeat:" details) |
| 25 | + (.heartbeat ctx (nippy/freeze details)))) |
| 26 | + |
| 27 | +(defn get-heartbeat-details |
| 28 | + " |
| 29 | +Extracts Heartbeat details from the last failed attempt. This is used in combination with retry options. An Activity |
| 30 | +Execution could be scheduled with optional [[temporal.common/retry-options]]. If an Activity Execution failed then the |
| 31 | +server would attempt to dispatch another Activity Task to retry the execution according to the retry options. If there |
| 32 | +were Heartbeat details reported by [[heartbeat]] in the last Activity Execution that failed, they would be delivered |
| 33 | +along with the Activity Task for the next retry attempt and can be extracted by the Activity implementation. |
| 34 | +" |
| 35 | + [] |
| 36 | + |
| 37 | + (let [ctx (Activity/getExecutionContext) |
| 38 | + details (.getHeartbeatDetails ctx u/bytes-type)] |
| 39 | + (let [v (when (.isPresent details) |
| 40 | + (nippy/thaw (.get details)))] |
| 41 | + (log/trace "get-heartbeat-details:" v) |
| 42 | + v))) |
12 | 43 |
|
13 | 44 | (defn- complete-invoke
|
14 | 45 | [activity result]
|
|
0 commit comments