Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c60dc29

Browse files
authored
Worker versioning (temporalio#1146)
Support for the new Worker Versioning feature
1 parent 7751b57 commit c60dc29

14 files changed

+1101
-264
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ packages/test/protos/root.d.ts
99
packages/testing/test-server*
1010
packages/testing/generated-protos/
1111
packages/core-bridge/releases
12-
packages/*/package-lock.json
12+
packages/*/package-lock.json
13+
/sdk-node.iml

packages/client/src/build-id-types.ts

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import { temporal } from '@temporalio/proto';
2+
3+
/**
4+
* Operations that can be passed to {@link TaskQueueClient.updateBuildIdCompatibility}.
5+
*
6+
* @experimental
7+
*/
8+
export type BuildIdOperation =
9+
| AddNewIdInNewDefaultSet
10+
| AddNewCompatibleVersion
11+
| PromoteSetByBuildId
12+
| PromoteBuildIdWithinSet
13+
| MergeSets;
14+
15+
/**
16+
* Adds a new Build Id into a new set, which will be used as the default set for
17+
* the queue. This means all new workflows will start on this Build Id.
18+
*
19+
* @experimental
20+
*/
21+
export interface AddNewIdInNewDefaultSet {
22+
operation: 'addNewIdInNewDefaultSet';
23+
buildId: string;
24+
}
25+
26+
/**
27+
* Adds a new Build Id into an existing compatible set. The newly added ID becomes
28+
* the default for that compatible set, and thus new workflow tasks for workflows which have been
29+
* executing on workers in that set will now start on this new Build Id.
30+
*
31+
* @experimental
32+
*/
33+
export interface AddNewCompatibleVersion {
34+
operation: 'addNewCompatibleVersion';
35+
// The Build Id to add to an existing compatible set.
36+
buildId: string;
37+
// A Build Id which must already be defined on the task queue, and is used to
38+
// find the compatible set to add the new id to.
39+
existingCompatibleBuildId: string;
40+
// If set to true, the targeted set will also be promoted to become the
41+
// overall default set for the queue.
42+
promoteSet?: boolean;
43+
}
44+
45+
/**
46+
* Promotes a set of compatible Build Ids to become the current
47+
* default set for the task queue. Any Build Id in the set may be used to
48+
* target it.
49+
*
50+
* @experimental
51+
*/
52+
export interface PromoteSetByBuildId {
53+
operation: 'promoteSetByBuildId';
54+
buildId: string;
55+
}
56+
57+
/**
58+
* Promotes a Build Id within an existing set to become the default ID for that
59+
* set.
60+
*
61+
* @experimental
62+
*/
63+
export interface PromoteBuildIdWithinSet {
64+
operation: 'promoteBuildIdWithinSet';
65+
buildId: string;
66+
}
67+
68+
/**
69+
* Merges two sets into one set, thus declaring all the Build Ids in both as
70+
* compatible with one another. The default of the primary set is maintained as
71+
* the merged set's overall default.
72+
*
73+
* @experimental
74+
*/
75+
export interface MergeSets {
76+
operation: 'mergeSets';
77+
// A Build Id which is used to find the primary set to be merged.
78+
primaryBuildId: string;
79+
// A Build Id which is used to find the secondary set to be merged.
80+
secondaryBuildId: string;
81+
}
82+
83+
/**
84+
* Represents the sets of compatible Build Id versions associated with some
85+
* Task Queue, as fetched by {@link TaskQueueClient.getBuildIdCompatability}.
86+
*
87+
* @experimental
88+
*/
89+
export interface WorkerBuildIdVersionSets {
90+
/**
91+
* All version sets that were fetched for this task queue.
92+
*/
93+
readonly versionSets: BuildIdVersionSet[];
94+
95+
/**
96+
* Returns the default set of compatible Build Ids for the task queue these sets are
97+
* associated with.
98+
*/
99+
defaultSet: BuildIdVersionSet;
100+
101+
/**
102+
* Returns the overall default Build Id for the task queue these sets are
103+
* associated with.
104+
*/
105+
defaultBuildId: string;
106+
}
107+
108+
/**
109+
* Represents one set of compatible Build Ids.
110+
*
111+
* @experimental
112+
*/
113+
export interface BuildIdVersionSet {
114+
// All build IDs contained in the set.
115+
readonly buildIds: string[];
116+
117+
// Returns the default Build Id for this set
118+
readonly default: string;
119+
}
120+
121+
export function versionSetsFromProto(
122+
resp: temporal.api.workflowservice.v1.GetWorkerBuildIdCompatibilityResponse
123+
): WorkerBuildIdVersionSets {
124+
if (resp == null || resp.majorVersionSets == null || resp.majorVersionSets.length === 0) {
125+
throw new Error('Must be constructed from a compatability response with at least one version set');
126+
}
127+
return {
128+
versionSets: resp.majorVersionSets.map((set) => versionSetFromProto(set)),
129+
get defaultSet(): BuildIdVersionSet {
130+
return this.versionSets[this.versionSets.length - 1];
131+
},
132+
get defaultBuildId(): string {
133+
return this.defaultSet.default;
134+
},
135+
};
136+
}
137+
138+
function versionSetFromProto(set: temporal.api.taskqueue.v1.ICompatibleVersionSet): BuildIdVersionSet {
139+
if (set == null || set.buildIds == null || set.buildIds.length === 0) {
140+
throw new Error('Compatible version sets must contain at least one Build Id');
141+
}
142+
return {
143+
buildIds: set.buildIds,
144+
default: set.buildIds[set.buildIds.length - 1],
145+
};
146+
}

packages/client/src/client.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ClientInterceptors } from './interceptors';
66
import { ScheduleClient } from './schedule-client';
77
import { WorkflowService } from './types';
88
import { WorkflowClient } from './workflow-client';
9+
import { TaskQueueClient } from './task-queue-client';
910

1011
export interface ClientOptions extends BaseClientOptions {
1112
/**
@@ -46,6 +47,12 @@ export class Client extends BaseClient {
4647
* @experimental
4748
*/
4849
public readonly schedule: ScheduleClient;
50+
/**
51+
* Task Queue sub-client - use to perform operations on Task Queues
52+
*
53+
* @experimental
54+
*/
55+
public readonly taskQueue: TaskQueueClient;
4956

5057
constructor(options?: ClientOptions) {
5158
super(options);
@@ -73,6 +80,12 @@ export class Client extends BaseClient {
7380
interceptors: interceptors?.schedule,
7481
});
7582

83+
this.taskQueue = new TaskQueueClient({
84+
...commonOptions,
85+
connection: this.connection,
86+
dataConverter: this.dataConverter,
87+
});
88+
7689
this.options = {
7790
...defaultBaseClientOptions(),
7891
...filterNullAndUndefined(commonOptions),

packages/client/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ export * from './workflow-client';
3838
export * from './workflow-options';
3939
export * from './schedule-types';
4040
export * from './schedule-client';
41+
export * from './task-queue-client';
42+
export {
43+
WorkerBuildIdVersionSets,
44+
BuildIdVersionSet,
45+
BuildIdOperation,
46+
PromoteSetByBuildId,
47+
PromoteBuildIdWithinSet,
48+
MergeSets,
49+
AddNewIdInNewDefaultSet,
50+
AddNewCompatibleVersion,
51+
} from './build-id-types';

0 commit comments

Comments
 (0)