Skip to content

Commit 215920a

Browse files
💥 Standalone activities support (#2158)
* Implemented standalone activities * Addressed some PR comments * Added interceptor methods and ActivityHandleBase. * ClientGetActivityHandleOptions * Add docs, mark everything experimental, add details to go along with summary, * Return err for ActivityExecutionAlreadyStarted, unless reuse policy allows it * Intercept cancel/terminate/describe/PollActivityResult, bump dev server to 1.5.2-standalone-activity-server * go mod tidy * ClientListActivitiesResult, mirror ClientPollWorkflowUpdateOutput, cache results, clarify CompleteActivity* docs, add ActivityExecutionErrorWhenAlreadyStarted * Fix condition * upgrade CLI version to 1.6.1-server-1.31.0-150.0, fix test * return err for ListActivities for future-proofing, * add SA for dynamic config to docker yaml for CI * Skip SA integration test for docker tests * remove extra quote * Missed a test to skip --------- Co-authored-by: Andrew Yuan <Andrew.Yuan@temporal.io>
1 parent 6c2f815 commit 215920a

44 files changed

Lines changed: 2169 additions & 219 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ jobs:
9999
# TODO(antlai-temporal): Remove this flag once server 1.27 released.
100100
DISABLE_SERVER_1_27_TESTS: "1"
101101
DISABLE_PRIORITY_TESTS: "1"
102+
DISABLE_STANDALONE_ACTIVITY_TESTS: "1"
102103
working-directory: ./internal/cmd/build
103104

104105
cloud-test:

‎.github/workflows/docker/dynamic-config-custom.yaml‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ component.callbacks.allowedAddresses:
4141
component.nexusoperations.recordCancelRequestCompletionEvents:
4242
- value: true
4343
frontend.activityAPIsEnabled:
44-
- value: true
44+
- value: true
45+
activity.enableStandalone:
46+
- value: true
47+
history.enableChasm:
48+
- value: true
49+
history.enableTransitionHistory:
50+
- value: true
51+
component.nexusoperations.useSystemCallbackURL:
52+
- value: false

‎client/client.go‎

Lines changed: 140 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ package client
88
import (
99
"context"
1010
"crypto/tls"
11-
"io"
12-
1311
commonpb "go.temporal.io/api/common/v1"
1412
enumspb "go.temporal.io/api/enums/v1"
1513
historypb "go.temporal.io/api/history/v1"
1614
"go.temporal.io/api/operatorservice/v1"
1715
"go.temporal.io/api/workflowservice/v1"
16+
"io"
1817

1918
"go.temporal.io/sdk/converter"
2019
"go.temporal.io/sdk/internal"
@@ -896,6 +895,80 @@ type (
896895
// Note, this is not related to any general concept of timing out or cancelling a running update, this is only related to the client call itself.
897896
WorkflowUpdateServiceTimeoutOrCanceledError = internal.WorkflowUpdateServiceTimeoutOrCanceledError
898897

898+
// StartActivityOptions contains configuration parameters for starting an activity execution from the client.
899+
// ID and TaskQueue are required. At least one of ScheduleToCloseTimeout or StartToCloseTimeout is required.
900+
// Other parameters are optional.
901+
//
902+
// NOTE: Experimental
903+
StartActivityOptions = internal.ClientStartActivityOptions
904+
905+
// GetActivityHandleOptions contains input for GetActivityHandle call.
906+
// ActivityID and RunID are required.
907+
//
908+
// NOTE: Experimental
909+
GetActivityHandleOptions = internal.ClientGetActivityHandleOptions
910+
911+
// ListActivitiesOptions contains input for ListActivities call.
912+
//
913+
// NOTE: Experimental
914+
ListActivitiesOptions = internal.ClientListActivitiesOptions
915+
916+
// ListActivitiesResult contains the result of the ListActivities call.
917+
//
918+
// NOTE: Experimental
919+
ListActivitiesResult = internal.ClientListActivitiesResult
920+
921+
// CountActivitiesOptions contains input for CountActivities call.
922+
//
923+
// NOTE: Experimental
924+
CountActivitiesOptions = internal.ClientCountActivitiesOptions
925+
926+
// CountActivitiesResult contains the result of the CountActivities call.
927+
//
928+
// NOTE: Experimental
929+
CountActivitiesResult = internal.ClientCountActivitiesResult
930+
931+
// CountActivitiesAggregationGroup contains groups of activities if
932+
// CountActivityExecutions is grouped by a field.
933+
// The list might not be complete, and the counts of each group is approximate.
934+
//
935+
// NOTE: Experimental
936+
CountActivitiesAggregationGroup = internal.ClientCountActivitiesAggregationGroup
937+
938+
// ActivityHandle represents a running or completed standalone activity execution.
939+
// It can be used to get the result, describe, cancel, or terminate the activity.
940+
//
941+
// NOTE: Experimental
942+
ActivityHandle = internal.ClientActivityHandle
943+
944+
// ActivityExecutionInfo contains information about an activity execution.
945+
// This is returned by ListActivities and embedded in ClientActivityExecutionDescription.
946+
//
947+
// NOTE: Experimental
948+
ActivityExecutionInfo = internal.ClientActivityExecutionInfo
949+
950+
// ActivityExecutionDescription contains detailed information about an activity execution.
951+
// This is returned by ClientActivityHandle.Describe.
952+
//
953+
// NOTE: Experimental
954+
ActivityExecutionDescription = internal.ClientActivityExecutionDescription
955+
956+
// DescribeActivityOptions contains options for ClientActivityHandle.Describe call.
957+
// For future compatibility, currently unused.
958+
//
959+
// NOTE: Experimental
960+
DescribeActivityOptions = internal.ClientDescribeActivityOptions
961+
962+
// CancelActivityOptions contains options for ClientActivityHandle.Cancel call.
963+
//
964+
// NOTE: Experimental
965+
CancelActivityOptions = internal.ClientCancelActivityOptions
966+
967+
// TerminateActivityOptions contains options for ClientActivityHandle.Terminate call.
968+
//
969+
// NOTE: Experimental
970+
TerminateActivityOptions = internal.ClientTerminateActivityOptions
971+
899972
// Client is the client for starting and getting information about a workflow executions as well as
900973
// completing activities asynchronously.
901974
Client interface {
@@ -1022,11 +1095,10 @@ type (
10221095
GetWorkflowHistory(ctx context.Context, workflowID string, runID string, isLongPoll bool, filterType enumspb.HistoryEventFilterType) HistoryEventIterator
10231096

10241097
// CompleteActivity reports activity completed.
1025-
// activity Execute method can return activity.ErrResultPending to
1026-
// indicate the activity is not completed when it's Execute method returns. In that case, this CompleteActivity() method
1027-
// should be called when that activity is completed with the actual result and error. If err is nil, activity task
1028-
// completed event will be reported; if err is CanceledError, activity task canceled event will be reported; otherwise,
1029-
// activity task failed event will be reported.
1098+
// An activity's implementation can return activity.ErrResultPending to indicate it will be completed asynchronously.
1099+
// In that case, this CompleteActivity() method should be called when the activity is completed with the
1100+
// actual result and error. If err is nil, activity task completed event will be reported; if err is CanceledError,
1101+
// activity task canceled event will be reported; otherwise, activity task failed event will be reported.
10301102
// An activity implementation should use GetActivityInfo(ctx).TaskToken function to get task token to use for completion.
10311103
// Example:-
10321104
// To complete with a result.
@@ -1037,20 +1109,39 @@ type (
10371109
CompleteActivity(ctx context.Context, taskToken []byte, result interface{}, err error) error
10381110

10391111
// CompleteActivityByID reports activity completed.
1040-
// Similar to CompleteActivity, but may save user from keeping taskToken info.
1041-
// activity Execute method can return activity.ErrResultPending to
1042-
// indicate the activity is not completed when it's Execute method returns. In that case, this CompleteActivityById() method
1043-
// should be called when that activity is completed with the actual result and error. If err is nil, activity task
1044-
// completed event will be reported; if err is CanceledError, activity task canceled event will be reported; otherwise,
1045-
// activity task failed event will be reported.
1112+
// Similar to CompleteActivity, but may save the user from keeping taskToken info.
1113+
// This method works only for workflow activities. workflowID and runID must be set to the workflow ID and workflow run ID
1114+
// of the workflow that started the activity. To complete a standalone activity (not started by workflow),
1115+
// use CompleteActivityByActivityID.
1116+
//
1117+
// An activity's implementation can return activity.ErrResultPending to indicate it will be completed asynchronously.
1118+
// In that case, this CompleteActivityByID() method should be called when the activity is completed with the
1119+
// actual result and error. If err is nil, activity task completed event will be reported; if err is CanceledError,
1120+
// activity task canceled event will be reported; otherwise, activity task failed event will be reported.
10461121
// An activity implementation should use activityID provided in ActivityOption to use for completion.
1047-
// namespace name, workflowID, activityID are required, runID is optional.
1122+
// namespace, workflowID and activityID are required, runID is optional.
10481123
// The errors it can return:
10491124
// - ApplicationError
10501125
// - TimeoutError
10511126
// - CanceledError
10521127
CompleteActivityByID(ctx context.Context, namespace, workflowID, runID, activityID string, result interface{}, err error) error
10531128

1129+
// CompleteActivityByActivityID reports activity completed.
1130+
// Similar to CompleteActivity, but may save the user from keeping taskToken info.
1131+
// This method works only for standalone activities. To complete a workflow activity, use CompleteActivityByID.
1132+
//
1133+
// An activity's implementation can return activity.ErrResultPending to indicate it will be completed asynchronously.
1134+
// In that case, this CompleteActivityByActivityID() method should be called when the activity is completed with the
1135+
// actual result and error. If err is nil, activity task completed event will be reported; if err is CanceledError,
1136+
// activity task canceled event will be reported; otherwise, activity task failed event will be reported.
1137+
// An activity implementation should use activityID provided in ActivityOption to use for completion.
1138+
// namespace and activityID are required, activityRunID is optional.
1139+
// The errors it can return:
1140+
// - ApplicationError
1141+
// - TimeoutError
1142+
// - CanceledError
1143+
CompleteActivityByActivityID(ctx context.Context, namespace, activityID, activityRunID string, result interface{}, err error) error
1144+
10541145
// RecordActivityHeartbeat records heartbeat for an activity.
10551146
// taskToken - is the value of the binary "TaskToken" field of the "ActivityInfo" struct retrieved inside the activity.
10561147
// details - is the progress you want to record along with heart beat for this activity. If the activity is canceled,
@@ -1306,6 +1397,41 @@ type (
13061397
// if not specified the most recent runID will be used.
13071398
GetWorkflowUpdateHandle(ref GetWorkflowUpdateHandleOptions) WorkflowUpdateHandle
13081399

1400+
// ExecuteActivity starts a standalone activity execution and returns an ActivityHandle.
1401+
// The user can use this to start using a function or activity type name.
1402+
// Either by
1403+
// ExecuteActivity(ctx, options, "activityTypeName", arg1, arg2, arg3)
1404+
// or
1405+
// ExecuteActivity(ctx, options, activityFn, arg1, arg2, arg3)
1406+
//
1407+
// Returns an ActivityExecutionAlreadyStarted error if an activity with the same ID already exists
1408+
// in this namespace, unless permitted by the specified ID conflict policy.
1409+
//
1410+
// NOTE: Standalone activities are not associated with a workflow execution.
1411+
// They are scheduled directly on a task queue and executed by a worker.
1412+
//
1413+
// NOTE: Experimental
1414+
ExecuteActivity(ctx context.Context, options StartActivityOptions, activity any, args ...any) (ActivityHandle, error)
1415+
1416+
// GetActivityHandle creates a handle to the referenced activity.
1417+
//
1418+
// NOTE: Experimental
1419+
GetActivityHandle(options GetActivityHandleOptions) ActivityHandle
1420+
1421+
// ListActivities lists activity executions based on query.
1422+
//
1423+
// Currently, all errors are returned in the iterator and not the base level error.
1424+
//
1425+
// NOTE: Experimental
1426+
ListActivities(ctx context.Context, options ListActivitiesOptions) (ListActivitiesResult, error)
1427+
1428+
// CountActivities counts activity executions based on query. The result
1429+
// includes the total count and optionally grouped counts if the query includes
1430+
// a GROUP BY clause.
1431+
//
1432+
// NOTE: Experimental
1433+
CountActivities(ctx context.Context, options CountActivitiesOptions) (*CountActivitiesResult, error)
1434+
13091435
// WorkflowService provides access to the underlying gRPC service. This should only be used for advanced use cases
13101436
// that cannot be accomplished via other Client methods. Unlike calls to other Client methods, calls directly to the
13111437
// service are not configured with internal semantics such as automatic retries.

‎contrib/datadog/go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ require (
8181
go.opentelemetry.io/otel/metric v1.37.0 // indirect
8282
go.opentelemetry.io/otel/sdk v1.37.0 // indirect
8383
go.opentelemetry.io/otel/trace v1.37.0 // indirect
84-
go.temporal.io/api v1.59.0 // indirect
84+
go.temporal.io/api v1.62.0 // indirect
8585
go.uber.org/atomic v1.11.0 // indirect
8686
go.uber.org/multierr v1.11.0 // indirect
8787
go.uber.org/zap v1.27.0 // indirect

‎contrib/datadog/go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ go.opentelemetry.io/proto/slim/otlp/collector/profiles/v1development v0.0.1 h1:T
233233
go.opentelemetry.io/proto/slim/otlp/collector/profiles/v1development v0.0.1/go.mod h1:riqUmAOJFDFuIAzZu/3V6cOrTyfWzpgNJnG5UwrapCk=
234234
go.opentelemetry.io/proto/slim/otlp/profiles/v1development v0.0.1 h1:z/oMlrCv3Kopwh/dtdRagJy+qsRRPA86/Ux3g7+zFXM=
235235
go.opentelemetry.io/proto/slim/otlp/profiles/v1development v0.0.1/go.mod h1:C7EHYSIiaALi9RnNORCVaPCQDuJgJEn/XxkctaTez1E=
236-
go.temporal.io/api v1.59.0 h1:QUpAju1KKs9xBfGSI0Uwdyg06k6dRCJH+Zm3G1Jc9Vk=
237-
go.temporal.io/api v1.59.0/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
236+
go.temporal.io/api v1.62.0 h1:rh7LqqV+pxaLNwPLsFRZgYoDJ/NvCNDv0EnWe6oS7A4=
237+
go.temporal.io/api v1.62.0/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
238238
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
239239
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
240240
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=

‎contrib/envconfig/go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/pmezard/go-difflib v1.0.0 // indirect
2323
github.com/robfig/cron v1.2.0 // indirect
2424
github.com/stretchr/objx v0.5.2 // indirect
25-
go.temporal.io/api v1.59.0 // indirect
25+
go.temporal.io/api v1.62.0 // indirect
2626
golang.org/x/net v0.39.0 // indirect
2727
golang.org/x/sync v0.13.0 // indirect
2828
golang.org/x/sys v0.32.0 // indirect

‎contrib/envconfig/go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf
3737
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
3838
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
3939
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
40-
go.temporal.io/api v1.59.0 h1:QUpAju1KKs9xBfGSI0Uwdyg06k6dRCJH+Zm3G1Jc9Vk=
41-
go.temporal.io/api v1.59.0/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
40+
go.temporal.io/api v1.62.0 h1:rh7LqqV+pxaLNwPLsFRZgYoDJ/NvCNDv0EnWe6oS7A4=
41+
go.temporal.io/api v1.62.0/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
4242
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
4343
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
4444
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

‎contrib/opentelemetry/go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/stretchr/objx v0.5.2 // indirect
3333
go.opentelemetry.io/otel/metric v1.27.0
3434
go.opentelemetry.io/otel/sdk/metric v1.27.0
35-
go.temporal.io/api v1.59.0 // indirect
35+
go.temporal.io/api v1.62.0 // indirect
3636
golang.org/x/net v0.39.0 // indirect
3737
golang.org/x/sys v0.32.0 // indirect
3838
golang.org/x/text v0.24.0 // indirect

‎contrib/opentelemetry/go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ go.opentelemetry.io/otel/sdk/metric v1.27.0 h1:5uGNOlpXi+Hbo/DRoI31BSb1v+OGcpv2N
5050
go.opentelemetry.io/otel/sdk/metric v1.27.0/go.mod h1:we7jJVrYN2kh3mVBlswtPU22K0SA+769l93J6bsyvqw=
5151
go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw=
5252
go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4=
53-
go.temporal.io/api v1.59.0 h1:QUpAju1KKs9xBfGSI0Uwdyg06k6dRCJH+Zm3G1Jc9Vk=
54-
go.temporal.io/api v1.59.0/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
53+
go.temporal.io/api v1.62.0 h1:rh7LqqV+pxaLNwPLsFRZgYoDJ/NvCNDv0EnWe6oS7A4=
54+
go.temporal.io/api v1.62.0/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
5555
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
5656
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
5757
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

‎contrib/opentracing/go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/pmezard/go-difflib v1.0.0 // indirect
2323
github.com/robfig/cron v1.2.0 // indirect
2424
github.com/stretchr/objx v0.5.2 // indirect
25-
go.temporal.io/api v1.59.0 // indirect
25+
go.temporal.io/api v1.62.0 // indirect
2626
golang.org/x/net v0.39.0 // indirect
2727
golang.org/x/sync v0.13.0 // indirect
2828
golang.org/x/sys v0.32.0 // indirect

0 commit comments

Comments
 (0)