Skip to content

Commit 8cebcf5

Browse files
committed
Standalone activity prototype -- ID reuse/conflict policies (#650)
Use execution-specific ID reuse & conflict policies instead of introducing shared policies for all CHASM executions.
1 parent 382dac7 commit 8cebcf5

File tree

6 files changed

+80
-90
lines changed

6 files changed

+80
-90
lines changed

openapi/openapiv2.json

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10138,12 +10138,12 @@
1013810138
"description": "Serialized arguments to the activity. These are passed as arguments to the activity function."
1013910139
},
1014010140
"idReusePolicy": {
10141-
"$ref": "#/definitions/v1IdReusePolicy",
10142-
"description": "Defines whether to allow re-using the activity id from a previously *closed* activity.\nThe default policy is ID_REUSE_POLICY_ALLOW_DUPLICATE."
10141+
"$ref": "#/definitions/v1ActivityIdReusePolicy",
10142+
"description": "Defines whether to allow re-using the activity id from a previously *closed* activity.\nThe default policy is ACTIVITY_ID_REUSE_POLICY_ALLOW_DUPLICATE."
1014310143
},
1014410144
"idConflictPolicy": {
10145-
"$ref": "#/definitions/v1IdConflictPolicy",
10146-
"description": "Defines how to resolve an activity id conflict with a *running* activity.\nThe default policy is ID_CONFLICT_POLICY_FAIL."
10145+
"$ref": "#/definitions/v1ActivityIdConflictPolicy",
10146+
"description": "Defines how to resolve an activity id conflict with a *running* activity.\nThe default policy is ACTIVITY_ID_CONFLICT_POLICY_FAIL."
1014710147
},
1014810148
"memo": {
1014910149
"$ref": "#/definitions/v1Memo",
@@ -10183,7 +10183,7 @@
1018310183
},
1018410184
"onConflictOptions": {
1018510185
"$ref": "#/definitions/apiactivityv1OnConflictOptions",
10186-
"description": "Defines actions to be done to the existing running activity when ID_CONFLICT_POLICY_USE_EXISTING is used. If not\nset or empty, it won't do anything to the existing running activity."
10186+
"description": "Defines actions to be done to the existing running activity when ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING is used. If not\nset or empty, it won't do anything to the existing running activity."
1018710187
},
1018810188
"priority": {
1018910189
"$ref": "#/definitions/v1Priority",
@@ -10818,7 +10818,7 @@
1081810818
"description": "Attaches the links to the WorkflowExecutionOptionsUpdatedEvent history event."
1081910819
}
1082010820
},
10821-
"description": "When StartActivityExecution uses the ID_CONFLICT_POLICY_USE_EXISTING and there is already an existing running\nactivity, OnConflictOptions defines actions to be taken on the existing running activity, updating its state."
10821+
"description": "When StartActivityExecution uses the ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING and there is already an existing running\nactivity, OnConflictOptions defines actions to be taken on the existing running activity, updating its state."
1082210822
},
1082310823
"apicommonv1Link": {
1082410824
"type": "object",
@@ -11219,6 +11219,28 @@
1121911219
}
1122011220
}
1122111221
},
11222+
"v1ActivityIdConflictPolicy": {
11223+
"type": "string",
11224+
"enum": [
11225+
"ACTIVITY_ID_CONFLICT_POLICY_UNSPECIFIED",
11226+
"ACTIVITY_ID_CONFLICT_POLICY_FAIL",
11227+
"ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING",
11228+
"ACTIVITY_ID_CONFLICT_POLICY_TERMINATE_EXISTING"
11229+
],
11230+
"default": "ACTIVITY_ID_CONFLICT_POLICY_UNSPECIFIED",
11231+
"description": "Defines what to do when trying to start an activity with the same ID as a *running* activity.\nNote that it is *never* valid to have two running instances of the same activity ID.\n\nSee `ActivityIdReusePolicy` for handling activity ID duplication with a *closed* activity.\n\n - ACTIVITY_ID_CONFLICT_POLICY_FAIL: Don't start a new activity; instead return `ActivityExecutionAlreadyStarted` error.\n - ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING: Don't start a new activity; instead return a handle for the running activity.\n - ACTIVITY_ID_CONFLICT_POLICY_TERMINATE_EXISTING: Terminate the running activity before starting a new one."
11232+
},
11233+
"v1ActivityIdReusePolicy": {
11234+
"type": "string",
11235+
"enum": [
11236+
"ACTIVITY_ID_REUSE_POLICY_UNSPECIFIED",
11237+
"ACTIVITY_ID_REUSE_POLICY_ALLOW_DUPLICATE",
11238+
"ACTIVITY_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY",
11239+
"ACTIVITY_ID_REUSE_POLICY_REJECT_DUPLICATE"
11240+
],
11241+
"default": "ACTIVITY_ID_REUSE_POLICY_UNSPECIFIED",
11242+
"description": "Defines whether to allow re-using an activity ID from a previously *closed* activity.\nIf the request is denied, the server returns an `ActivityExecutionAlreadyStarted` error.\n\nSee `ActivityIdConflictPolicy` for handling ID duplication with a *running* activity.\n\n - ACTIVITY_ID_REUSE_POLICY_ALLOW_DUPLICATE: Always allow starting an activity using the same activity ID.\n - ACTIVITY_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY: Allow starting an activity using the same ID only when the last activity's final state is one\nof {failed, canceled, terminated, timed out}.\n - ACTIVITY_ID_REUSE_POLICY_REJECT_DUPLICATE: Do not permit re-use of the ID for this activity. Future start requests could potentially change the policy,\nallowing re-use of the ID."
11243+
},
1122211244
"v1ActivityListInfo": {
1122311245
"type": "object",
1122411246
"properties": {
@@ -13850,28 +13872,6 @@
1385013872
],
1385113873
"default": "HISTORY_EVENT_FILTER_TYPE_UNSPECIFIED"
1385213874
},
13853-
"v1IdConflictPolicy": {
13854-
"type": "string",
13855-
"enum": [
13856-
"ID_CONFLICT_POLICY_UNSPECIFIED",
13857-
"ID_CONFLICT_POLICY_FAIL",
13858-
"ID_CONFLICT_POLICY_USE_EXISTING",
13859-
"ID_CONFLICT_POLICY_TERMINATE_EXISTING"
13860-
],
13861-
"default": "ID_CONFLICT_POLICY_UNSPECIFIED",
13862-
"description": "Defines what to do when trying to start an execution with the same ID as a *running* execution.\nNote that it is *never* valid to have two actively running instances of the same execution ID.\n\nSee `IdReusePolicy` for handling execution ID duplication with a *closed* execution.\n\n - ID_CONFLICT_POLICY_FAIL: Don't start a new execution; instead return `ExecutionAlreadyStarted` error.\n - ID_CONFLICT_POLICY_USE_EXISTING: Don't start a new execution; instead return a handle for the running execution.\n - ID_CONFLICT_POLICY_TERMINATE_EXISTING: Terminate the running execution before starting a new one."
13863-
},
13864-
"v1IdReusePolicy": {
13865-
"type": "string",
13866-
"enum": [
13867-
"ID_REUSE_POLICY_UNSPECIFIED",
13868-
"ID_REUSE_POLICY_ALLOW_DUPLICATE",
13869-
"ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY",
13870-
"ID_REUSE_POLICY_REJECT_DUPLICATE"
13871-
],
13872-
"default": "ID_REUSE_POLICY_UNSPECIFIED",
13873-
"description": "Defines whether to allow re-using an ID from a previously *closed* execution.\nIf the request is denied, the server returns an `ExecutionAlreadyStarted` error.\n\nSee `IdConflictPolicy` for handling ID duplication with a *running* execution.\n\n - ID_REUSE_POLICY_ALLOW_DUPLICATE: Always allow starting an execution using the same entity ID.\n - ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY: Allow starting an execution using the same ID, only when the last execution's final state is one of [terminated,\ncancelled, timed out, failed].\n - ID_REUSE_POLICY_REJECT_DUPLICATE: Do not permit re-use of the ID for this execution. Future start requests could potentially change the policy,\nallowing re-use of the ID."
13874-
},
1387513875
"v1IndexedValueType": {
1387613876
"type": "string",
1387713877
"enum": [
@@ -16783,7 +16783,7 @@
1678316783
"properties": {
1678416784
"runId": {
1678516785
"type": "string",
16786-
"description": "The run ID of the activity that was started - or used (via ID_CONFLICT_POLICY_USE_EXISTING)."
16786+
"description": "The run ID of the activity that was started - or used (via ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING)."
1678716787
},
1678816788
"started": {
1678916789
"type": "boolean",

openapi/openapiv3.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11234,7 +11234,7 @@ components:
1123411234
type: boolean
1123511235
description: Attaches the links to the WorkflowExecutionOptionsUpdatedEvent history event.
1123611236
description: |-
11237-
When StartActivityExecution uses the ID_CONFLICT_POLICY_USE_EXISTING and there is already an existing running
11237+
When StartActivityExecution uses the ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING and there is already an existing running
1123811238
activity, OnConflictOptions defines actions to be taken on the existing running activity, updating its state.
1123911239
Outcome:
1124011240
type: object
@@ -13793,25 +13793,25 @@ components:
1379313793
description: Serialized arguments to the activity. These are passed as arguments to the activity function.
1379413794
idReusePolicy:
1379513795
enum:
13796-
- ID_REUSE_POLICY_UNSPECIFIED
13797-
- ID_REUSE_POLICY_ALLOW_DUPLICATE
13798-
- ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY
13799-
- ID_REUSE_POLICY_REJECT_DUPLICATE
13796+
- ACTIVITY_ID_REUSE_POLICY_UNSPECIFIED
13797+
- ACTIVITY_ID_REUSE_POLICY_ALLOW_DUPLICATE
13798+
- ACTIVITY_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY
13799+
- ACTIVITY_ID_REUSE_POLICY_REJECT_DUPLICATE
1380013800
type: string
1380113801
description: |-
1380213802
Defines whether to allow re-using the activity id from a previously *closed* activity.
13803-
The default policy is ID_REUSE_POLICY_ALLOW_DUPLICATE.
13803+
The default policy is ACTIVITY_ID_REUSE_POLICY_ALLOW_DUPLICATE.
1380413804
format: enum
1380513805
idConflictPolicy:
1380613806
enum:
13807-
- ID_CONFLICT_POLICY_UNSPECIFIED
13808-
- ID_CONFLICT_POLICY_FAIL
13809-
- ID_CONFLICT_POLICY_USE_EXISTING
13810-
- ID_CONFLICT_POLICY_TERMINATE_EXISTING
13807+
- ACTIVITY_ID_CONFLICT_POLICY_UNSPECIFIED
13808+
- ACTIVITY_ID_CONFLICT_POLICY_FAIL
13809+
- ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING
13810+
- ACTIVITY_ID_CONFLICT_POLICY_TERMINATE_EXISTING
1381113811
type: string
1381213812
description: |-
1381313813
Defines how to resolve an activity id conflict with a *running* activity.
13814-
The default policy is ID_CONFLICT_POLICY_FAIL.
13814+
The default policy is ACTIVITY_ID_CONFLICT_POLICY_FAIL.
1381513815
format: enum
1381613816
memo:
1381713817
allOf:
@@ -13854,7 +13854,7 @@ components:
1385413854
allOf:
1385513855
- $ref: '#/components/schemas/OnConflictOptions'
1385613856
description: |-
13857-
Defines actions to be done to the existing running activity when ID_CONFLICT_POLICY_USE_EXISTING is used. If not
13857+
Defines actions to be done to the existing running activity when ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING is used. If not
1385813858
set or empty, it won't do anything to the existing running activity.
1385913859
priority:
1386013860
allOf:
@@ -13865,7 +13865,7 @@ components:
1386513865
properties:
1386613866
runId:
1386713867
type: string
13868-
description: The run ID of the activity that was started - or used (via ID_CONFLICT_POLICY_USE_EXISTING).
13868+
description: The run ID of the activity that was started - or used (via ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING).
1386913869
started:
1387013870
type: boolean
1387113871
description: If true, a new activity was started.

temporal/api/activity/v1/message.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import "temporal/api/failure/v1/message.proto";
2020
import "temporal/api/taskqueue/v1/message.proto";
2121
import "temporal/api/sdk/v1/user_metadata.proto";
2222

23-
// When StartActivityExecution uses the ID_CONFLICT_POLICY_USE_EXISTING and there is already an existing running
23+
// When StartActivityExecution uses the ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING and there is already an existing running
2424
// activity, OnConflictOptions defines actions to be taken on the existing running activity, updating its state.
2525
message OnConflictOptions {
2626
// Attaches the request ID to the running workflow.

temporal/api/enums/v1/activity.proto

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,33 @@ enum ActivityExecutionStatus {
3838
// TODO: Clarify if there are other conditions where the activity can end up in timed out status.
3939
ACTIVITY_EXECUTION_STATUS_TIMED_OUT = 6;
4040
}
41+
42+
// Defines whether to allow re-using an activity ID from a previously *closed* activity.
43+
// If the request is denied, the server returns an `ActivityExecutionAlreadyStarted` error.
44+
//
45+
// See `ActivityIdConflictPolicy` for handling ID duplication with a *running* activity.
46+
enum ActivityIdReusePolicy {
47+
ACTIVITY_ID_REUSE_POLICY_UNSPECIFIED = 0;
48+
// Always allow starting an activity using the same activity ID.
49+
ACTIVITY_ID_REUSE_POLICY_ALLOW_DUPLICATE = 1;
50+
// Allow starting an activity using the same ID only when the last activity's final state is one
51+
// of {failed, canceled, terminated, timed out}.
52+
ACTIVITY_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY = 2;
53+
// Do not permit re-use of the ID for this activity. Future start requests could potentially change the policy,
54+
// allowing re-use of the ID.
55+
ACTIVITY_ID_REUSE_POLICY_REJECT_DUPLICATE = 3;
56+
}
57+
58+
// Defines what to do when trying to start an activity with the same ID as a *running* activity.
59+
// Note that it is *never* valid to have two running instances of the same activity ID.
60+
//
61+
// See `ActivityIdReusePolicy` for handling activity ID duplication with a *closed* activity.
62+
enum ActivityIdConflictPolicy {
63+
ACTIVITY_ID_CONFLICT_POLICY_UNSPECIFIED = 0;
64+
// Don't start a new activity; instead return `ActivityExecutionAlreadyStarted` error.
65+
ACTIVITY_ID_CONFLICT_POLICY_FAIL = 1;
66+
// Don't start a new activity; instead return a handle for the running activity.
67+
ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING = 2;
68+
// Terminate the running activity before starting a new one.
69+
ACTIVITY_ID_CONFLICT_POLICY_TERMINATE_EXISTING = 3;
70+
}

temporal/api/enums/v1/id.proto

Lines changed: 0 additions & 40 deletions
This file was deleted.

temporal/api/workflowservice/v1/request_response.proto

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import "temporal/api/enums/v1/reset.proto";
1919
import "temporal/api/enums/v1/task_queue.proto";
2020
import "temporal/api/enums/v1/deployment.proto";
2121
import "temporal/api/enums/v1/update.proto";
22-
import "temporal/api/enums/v1/id.proto";
22+
import "temporal/api/enums/v1/activity.proto";
2323
import "temporal/api/activity/v1/message.proto";
2424
import "temporal/api/common/v1/message.proto";
2525
import "temporal/api/history/v1/message.proto";
@@ -2624,11 +2624,11 @@ message StartActivityExecutionRequest {
26242624
temporal.api.common.v1.Payloads input = 7;
26252625

26262626
// Defines whether to allow re-using the activity id from a previously *closed* activity.
2627-
// The default policy is ID_REUSE_POLICY_ALLOW_DUPLICATE.
2628-
temporal.api.enums.v1.IdReusePolicy id_reuse_policy = 8;
2627+
// The default policy is ACTIVITY_ID_REUSE_POLICY_ALLOW_DUPLICATE.
2628+
temporal.api.enums.v1.ActivityIdReusePolicy id_reuse_policy = 8;
26292629
// Defines how to resolve an activity id conflict with a *running* activity.
2630-
// The default policy is ID_CONFLICT_POLICY_FAIL.
2631-
temporal.api.enums.v1.IdConflictPolicy id_conflict_policy = 9;
2630+
// The default policy is ACTIVITY_ID_CONFLICT_POLICY_FAIL.
2631+
temporal.api.enums.v1.ActivityIdConflictPolicy id_conflict_policy = 9;
26322632

26332633
// Arbitrary structured data that can be attached to the activity execution and made available via the list and
26342634
// describe APIs.
@@ -2649,15 +2649,15 @@ message StartActivityExecutionRequest {
26492649
temporal.api.sdk.v1.UserMetadata user_metadata = 15;
26502650
// Links to be associated with the activity.
26512651
repeated temporal.api.common.v1.Link links = 16;
2652-
// Defines actions to be done to the existing running activity when ID_CONFLICT_POLICY_USE_EXISTING is used. If not
2652+
// Defines actions to be done to the existing running activity when ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING is used. If not
26532653
// set or empty, it won't do anything to the existing running activity.
26542654
temporal.api.activity.v1.OnConflictOptions on_conflict_options = 17;
26552655
// Priority metadata
26562656
temporal.api.common.v1.Priority priority = 18;
26572657
}
26582658

26592659
message StartActivityExecutionResponse {
2660-
// The run ID of the activity that was started - or used (via ID_CONFLICT_POLICY_USE_EXISTING).
2660+
// The run ID of the activity that was started - or used (via ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING).
26612661
string run_id = 1;
26622662
// If true, a new activity was started.
26632663
bool started = 2;

0 commit comments

Comments
 (0)