|
| 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 | +} |
0 commit comments