Skip to content

Commit 8e6d905

Browse files
authored
Document ErrResultPending's behavioral gap explicitly (#1229)
Resolving this "two kinds of finished-timeout / heartbeat-timeout" issue with ErrResultPending will need some new semantics on the server side... but at least there's a workaround until then. The general concept of a "pending activity" does seem worth supporting, particularly because it can respond with an "already completed" error when a second "complete" request is received. It just has unfortunate quirks at the moment.
1 parent 59996ea commit 8e6d905

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

activity/activity.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,23 @@ type (
4040
)
4141

4242
// ErrResultPending is returned from activity's implementation to indicate the activity is not completed when
43-
// activity method returns. Activity needs to be completed by Client.CompleteActivity() separately. For example, if an
44-
// activity require human interaction (like approve an expense report), the activity could return ErrResultPending
45-
// which indicate the activity is not done yet. Then, when the waited human action happened, it needs to trigger something
46-
// that could report the activity completed event to cadence server via Client.CompleteActivity() API.
43+
// activity method returns. The Activity needs to be completed by [go.uber.org/cadence/client.Client.CompleteActivity]
44+
// separately.
45+
//
46+
// For example, if an activity requires human interaction (like approving an expense report), the activity could push
47+
// its [Info.TaskToken] to an external system, and return [ErrResultPending]. Later on, a human can approve it, and the
48+
// system can use the associated token with [go.uber.org/cadence/client.Client.CompleteActivity] to finish the
49+
// still-"running" activity.
50+
//
51+
// Caution: since using this frequently implies "long" timeouts, but there is no actually-running activity function
52+
// that can use [go.uber.org/cadence/client.Client.RecordActivityHeartbeat], activity-worker losses prior to recording
53+
// the [Info.TaskToken] in an external system may not be noticed until the "long" timeout occurs. This can be resolved
54+
// by having another system call RecordActivityHeartbeat while that external action is running, but there is currently
55+
// no way to mitigate this issue without these heartbeats.
56+
//
57+
// If you cannot heartbeat and cannot tolerate this kind of delayed-activity-loss detection, consider emulating a long
58+
// activity via a signal channel instead: you can start a short-lived activity and wait for a "saved to external system"
59+
// signal, retrying as necessary, and then wait for an "external system finished" signal containing the final result.
4760
var ErrResultPending = internal.ErrActivityResultPending
4861

4962
// Register - calls RegisterWithOptions with default registration options.

0 commit comments

Comments
 (0)