@hatchet-dev/typescript-sdk 1.2.0-alpha.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/clients/admin/admin-client.d.ts +3 -1
- package/clients/admin/admin-client.js +1 -1
- package/clients/hatchet-client/features/cron-client.d.ts +3 -0
- package/clients/hatchet-client/features/cron-client.js +2 -0
- package/clients/hatchet-client/features/schedule-client.d.ts +3 -0
- package/clients/hatchet-client/features/schedule-client.js +2 -0
- package/clients/rest/generated/data-contracts.d.ts +24 -0
- package/clients/worker/worker.js +1 -0
- package/package.json +2 -3
- package/protoc/dispatcher/dispatcher.d.ts +1 -0
- package/protoc/dispatcher/dispatcher.js +17 -1
- package/protoc/v1/workflows.d.ts +2 -0
- package/protoc/v1/workflows.js +19 -1
- package/protoc/workflows/workflows.d.ts +2 -0
- package/protoc/workflows/workflows.js +17 -1
- package/step.d.ts +15 -34
- package/step.js +25 -42
- package/v1/client/client.d.ts +3 -11
- package/v1/client/client.interface.d.ts +0 -2
- package/v1/client/client.js +14 -35
- package/v1/client/worker.js +2 -4
- package/v1/declaration.d.ts +26 -3
- package/v1/declaration.js +55 -64
- package/v1/examples/cancellations/run.js +4 -4
- package/v1/examples/priority/run.js +41 -0
- package/v1/examples/{middleware → priority}/worker.js +3 -8
- package/v1/examples/priority/workflow.d.ts +8 -0
- package/v1/examples/priority/workflow.js +50 -0
- package/v1/index.d.ts +1 -0
- package/v1/index.js +1 -0
- package/v1/task.d.ts +0 -5
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/v1/examples/middleware/hatchet-client.d.ts +0 -2
- package/v1/examples/middleware/hatchet-client.js +0 -32
- package/v1/examples/middleware/run.js +0 -34
- package/v1/examples/middleware/workflow.d.ts +0 -9
- package/v1/examples/middleware/workflow.js +0 -37
- package/v1/next/index.d.ts +0 -1
- package/v1/next/index.js +0 -17
- package/v1/next/middleware/middleware.d.ts +0 -27
- package/v1/next/middleware/middleware.js +0 -121
- /package/v1/examples/{middleware → priority}/run.d.ts +0 -0
- /package/v1/examples/{middleware → priority}/worker.d.ts +0 -0
|
@@ -4,7 +4,7 @@ import { ClientConfig } from '../hatchet-client/client-config';
|
|
|
4
4
|
import { Logger } from '../../util/logger';
|
|
5
5
|
import WorkflowRunRef from '../../util/workflow-run-ref';
|
|
6
6
|
import { AdminServiceClient, CreateWorkflowVersionRequest } from '../../protoc/v1/workflows';
|
|
7
|
-
import { RunsClient } from '../../v1';
|
|
7
|
+
import { Priority, RunsClient } from '../../v1';
|
|
8
8
|
import { Api } from '../rest';
|
|
9
9
|
import { WebhookWorkerCreateRequest, WorkflowRunStatus, WorkflowRunStatusList } from '../rest/generated/data-contracts';
|
|
10
10
|
import { RunListenerClient } from '../listeners/run-listener/child-listener-client';
|
|
@@ -85,6 +85,7 @@ export declare class AdminClient {
|
|
|
85
85
|
childKey?: string | undefined;
|
|
86
86
|
additionalMetadata?: Record<string, string> | undefined;
|
|
87
87
|
desiredWorkerId?: string | undefined;
|
|
88
|
+
priority?: Priority;
|
|
88
89
|
}): WorkflowRunRef<P>;
|
|
89
90
|
/**
|
|
90
91
|
* Run multiple workflows runs with the given input and options. This will create new workflow runs and return their IDs.
|
|
@@ -102,6 +103,7 @@ export declare class AdminClient {
|
|
|
102
103
|
childKey?: string | undefined;
|
|
103
104
|
additionalMetadata?: Record<string, string> | undefined;
|
|
104
105
|
desiredWorkerId?: string | undefined;
|
|
106
|
+
priority?: Priority;
|
|
105
107
|
};
|
|
106
108
|
}>): Promise<WorkflowRunRef<P>[]>;
|
|
107
109
|
/**
|
|
@@ -124,7 +124,7 @@ class AdminClient {
|
|
|
124
124
|
const inputStr = JSON.stringify(input);
|
|
125
125
|
const resp = this.client.triggerWorkflow(Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
126
126
|
? JSON.stringify(options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
127
|
-
: undefined }));
|
|
127
|
+
: undefined, priority: options === null || options === void 0 ? void 0 : options.priority }));
|
|
128
128
|
return new workflow_run_ref_1.default(resp, this.listenerClient, this.workflows, options === null || options === void 0 ? void 0 : options.parentId);
|
|
129
129
|
}
|
|
130
130
|
catch (e) {
|
|
@@ -12,15 +12,18 @@ export declare const CreateCronTriggerSchema: z.ZodObject<{
|
|
|
12
12
|
expression: z.ZodEffects<z.ZodString, string, string>;
|
|
13
13
|
input: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
14
14
|
additionalMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
15
|
+
priority: z.ZodOptional<z.ZodNumber>;
|
|
15
16
|
}, "strip", z.ZodTypeAny, {
|
|
16
17
|
name: string;
|
|
17
18
|
expression: string;
|
|
18
19
|
additionalMetadata?: Record<string, string> | undefined;
|
|
20
|
+
priority?: number | undefined;
|
|
19
21
|
input?: Record<string, any> | undefined;
|
|
20
22
|
}, {
|
|
21
23
|
name: string;
|
|
22
24
|
expression: string;
|
|
23
25
|
additionalMetadata?: Record<string, string> | undefined;
|
|
26
|
+
priority?: number | undefined;
|
|
24
27
|
input?: Record<string, any> | undefined;
|
|
25
28
|
}>;
|
|
26
29
|
/**
|
|
@@ -24,6 +24,7 @@ exports.CreateCronTriggerSchema = zod_1.z.object({
|
|
|
24
24
|
}, 'Invalid cron expression'),
|
|
25
25
|
input: zod_1.z.record(zod_1.z.any()).optional(),
|
|
26
26
|
additionalMetadata: zod_1.z.record(zod_1.z.string()).optional(),
|
|
27
|
+
priority: zod_1.z.number().optional(),
|
|
27
28
|
});
|
|
28
29
|
/**
|
|
29
30
|
* Client for managing Cron Triggers.
|
|
@@ -70,6 +71,7 @@ class CronClient {
|
|
|
70
71
|
cronExpression: parsedCron.expression,
|
|
71
72
|
input: (_a = parsedCron.input) !== null && _a !== void 0 ? _a : {},
|
|
72
73
|
additionalMetadata: (_b = parsedCron.additionalMetadata) !== null && _b !== void 0 ? _b : {},
|
|
74
|
+
priority: parsedCron.priority,
|
|
73
75
|
});
|
|
74
76
|
return response.data;
|
|
75
77
|
}
|
|
@@ -11,13 +11,16 @@ export declare const CreateScheduledRunTriggerSchema: z.ZodObject<{
|
|
|
11
11
|
triggerAt: z.ZodDate;
|
|
12
12
|
input: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
13
13
|
additionalMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
14
|
+
priority: z.ZodOptional<z.ZodNumber>;
|
|
14
15
|
}, "strip", z.ZodTypeAny, {
|
|
15
16
|
triggerAt: Date;
|
|
16
17
|
additionalMetadata?: Record<string, string> | undefined;
|
|
18
|
+
priority?: number | undefined;
|
|
17
19
|
input?: Record<string, any> | undefined;
|
|
18
20
|
}, {
|
|
19
21
|
triggerAt: Date;
|
|
20
22
|
additionalMetadata?: Record<string, string> | undefined;
|
|
23
|
+
priority?: number | undefined;
|
|
21
24
|
input?: Record<string, any> | undefined;
|
|
22
25
|
}>;
|
|
23
26
|
/**
|
|
@@ -19,6 +19,7 @@ exports.CreateScheduledRunTriggerSchema = zod_1.z.object({
|
|
|
19
19
|
triggerAt: zod_1.z.coerce.date(),
|
|
20
20
|
input: zod_1.z.record(zod_1.z.any()).optional(),
|
|
21
21
|
additionalMetadata: zod_1.z.record(zod_1.z.string()).optional(),
|
|
22
|
+
priority: zod_1.z.number().optional(),
|
|
22
23
|
});
|
|
23
24
|
/**
|
|
24
25
|
* Client for managing Scheduled Runs.
|
|
@@ -64,6 +65,7 @@ class ScheduleClient {
|
|
|
64
65
|
input: (_a = parsedCron.input) !== null && _a !== void 0 ? _a : {},
|
|
65
66
|
additionalMetadata: (_b = parsedCron.additionalMetadata) !== null && _b !== void 0 ? _b : {},
|
|
66
67
|
triggerAt: parsedCron.triggerAt.toISOString(),
|
|
68
|
+
priority: parsedCron.priority,
|
|
67
69
|
});
|
|
68
70
|
return response.data;
|
|
69
71
|
}
|
|
@@ -705,6 +705,12 @@ export interface ScheduledWorkflows {
|
|
|
705
705
|
*/
|
|
706
706
|
workflowRunId?: string;
|
|
707
707
|
method: 'DEFAULT' | 'API';
|
|
708
|
+
/**
|
|
709
|
+
* @format int32
|
|
710
|
+
* @min 1
|
|
711
|
+
* @max 3
|
|
712
|
+
*/
|
|
713
|
+
priority?: number;
|
|
708
714
|
}
|
|
709
715
|
export interface ScheduledWorkflowsList {
|
|
710
716
|
rows?: ScheduledWorkflows[];
|
|
@@ -735,6 +741,12 @@ export interface CronWorkflows {
|
|
|
735
741
|
additionalMetadata?: Record<string, any>;
|
|
736
742
|
enabled: boolean;
|
|
737
743
|
method: 'DEFAULT' | 'API';
|
|
744
|
+
/**
|
|
745
|
+
* @format int32
|
|
746
|
+
* @min 1
|
|
747
|
+
* @max 3
|
|
748
|
+
*/
|
|
749
|
+
priority?: number;
|
|
738
750
|
}
|
|
739
751
|
export interface CronWorkflowsList {
|
|
740
752
|
rows?: CronWorkflows[];
|
|
@@ -1091,12 +1103,24 @@ export interface ScheduleWorkflowRunRequest {
|
|
|
1091
1103
|
additionalMetadata: object;
|
|
1092
1104
|
/** @format date-time */
|
|
1093
1105
|
triggerAt: string;
|
|
1106
|
+
/**
|
|
1107
|
+
* @format int32
|
|
1108
|
+
* @min 1
|
|
1109
|
+
* @max 3
|
|
1110
|
+
*/
|
|
1111
|
+
priority?: number;
|
|
1094
1112
|
}
|
|
1095
1113
|
export interface CreateCronWorkflowTriggerRequest {
|
|
1096
1114
|
input: object;
|
|
1097
1115
|
additionalMetadata: object;
|
|
1098
1116
|
cronName: string;
|
|
1099
1117
|
cronExpression: string;
|
|
1118
|
+
/**
|
|
1119
|
+
* @format int32
|
|
1120
|
+
* @min 1
|
|
1121
|
+
* @max 3
|
|
1122
|
+
*/
|
|
1123
|
+
priority?: number;
|
|
1100
1124
|
}
|
|
1101
1125
|
export interface CreatePullRequestFromStepRun {
|
|
1102
1126
|
branchName: string;
|
package/clients/worker/worker.js
CHANGED
|
@@ -199,6 +199,7 @@ class V0Worker {
|
|
|
199
199
|
sticky: workflow.sticky,
|
|
200
200
|
concurrency,
|
|
201
201
|
onFailureTask,
|
|
202
|
+
defaultPriority: workflow.defaultPriority,
|
|
202
203
|
tasks: [...workflow._tasks, ...workflow._durableTasks].map((task) => {
|
|
203
204
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
204
205
|
return ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "1.2.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -88,6 +88,5 @@
|
|
|
88
88
|
"qs": "^6.14.0",
|
|
89
89
|
"yaml": "^2.7.1",
|
|
90
90
|
"zod": "^3.24.2"
|
|
91
|
-
}
|
|
92
|
-
"packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0"
|
|
91
|
+
}
|
|
93
92
|
}
|
|
@@ -158,6 +158,7 @@ export interface AssignedAction {
|
|
|
158
158
|
childWorkflowKey?: string | undefined;
|
|
159
159
|
/** (optional) the parent workflow run id (if this is a child workflow) */
|
|
160
160
|
parentWorkflowRunId?: string | undefined;
|
|
161
|
+
priority: number;
|
|
161
162
|
}
|
|
162
163
|
export interface WorkerListenRequest {
|
|
163
164
|
/** the id of the worker */
|
|
@@ -1093,6 +1093,7 @@ function createBaseAssignedAction() {
|
|
|
1093
1093
|
childWorkflowIndex: undefined,
|
|
1094
1094
|
childWorkflowKey: undefined,
|
|
1095
1095
|
parentWorkflowRunId: undefined,
|
|
1096
|
+
priority: 0,
|
|
1096
1097
|
};
|
|
1097
1098
|
}
|
|
1098
1099
|
exports.AssignedAction = {
|
|
@@ -1148,6 +1149,9 @@ exports.AssignedAction = {
|
|
|
1148
1149
|
if (message.parentWorkflowRunId !== undefined) {
|
|
1149
1150
|
writer.uint32(138).string(message.parentWorkflowRunId);
|
|
1150
1151
|
}
|
|
1152
|
+
if (message.priority !== 0) {
|
|
1153
|
+
writer.uint32(144).int32(message.priority);
|
|
1154
|
+
}
|
|
1151
1155
|
return writer;
|
|
1152
1156
|
},
|
|
1153
1157
|
decode(input, length) {
|
|
@@ -1276,6 +1280,13 @@ exports.AssignedAction = {
|
|
|
1276
1280
|
message.parentWorkflowRunId = reader.string();
|
|
1277
1281
|
continue;
|
|
1278
1282
|
}
|
|
1283
|
+
case 18: {
|
|
1284
|
+
if (tag !== 144) {
|
|
1285
|
+
break;
|
|
1286
|
+
}
|
|
1287
|
+
message.priority = reader.int32();
|
|
1288
|
+
continue;
|
|
1289
|
+
}
|
|
1279
1290
|
}
|
|
1280
1291
|
if ((tag & 7) === 4 || tag === 0) {
|
|
1281
1292
|
break;
|
|
@@ -1313,6 +1324,7 @@ exports.AssignedAction = {
|
|
|
1313
1324
|
parentWorkflowRunId: isSet(object.parentWorkflowRunId)
|
|
1314
1325
|
? globalThis.String(object.parentWorkflowRunId)
|
|
1315
1326
|
: undefined,
|
|
1327
|
+
priority: isSet(object.priority) ? globalThis.Number(object.priority) : 0,
|
|
1316
1328
|
};
|
|
1317
1329
|
},
|
|
1318
1330
|
toJSON(message) {
|
|
@@ -1368,13 +1380,16 @@ exports.AssignedAction = {
|
|
|
1368
1380
|
if (message.parentWorkflowRunId !== undefined) {
|
|
1369
1381
|
obj.parentWorkflowRunId = message.parentWorkflowRunId;
|
|
1370
1382
|
}
|
|
1383
|
+
if (message.priority !== 0) {
|
|
1384
|
+
obj.priority = Math.round(message.priority);
|
|
1385
|
+
}
|
|
1371
1386
|
return obj;
|
|
1372
1387
|
},
|
|
1373
1388
|
create(base) {
|
|
1374
1389
|
return exports.AssignedAction.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
1375
1390
|
},
|
|
1376
1391
|
fromPartial(object) {
|
|
1377
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
1392
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
1378
1393
|
const message = createBaseAssignedAction();
|
|
1379
1394
|
message.tenantId = (_a = object.tenantId) !== null && _a !== void 0 ? _a : '';
|
|
1380
1395
|
message.workflowRunId = (_b = object.workflowRunId) !== null && _b !== void 0 ? _b : '';
|
|
@@ -1393,6 +1408,7 @@ exports.AssignedAction = {
|
|
|
1393
1408
|
message.childWorkflowIndex = (_q = object.childWorkflowIndex) !== null && _q !== void 0 ? _q : undefined;
|
|
1394
1409
|
message.childWorkflowKey = (_r = object.childWorkflowKey) !== null && _r !== void 0 ? _r : undefined;
|
|
1395
1410
|
message.parentWorkflowRunId = (_s = object.parentWorkflowRunId) !== null && _s !== void 0 ? _s : undefined;
|
|
1411
|
+
message.priority = (_t = object.priority) !== null && _t !== void 0 ? _t : 0;
|
|
1396
1412
|
return message;
|
|
1397
1413
|
},
|
|
1398
1414
|
};
|
package/protoc/v1/workflows.d.ts
CHANGED
|
@@ -97,6 +97,8 @@ export interface CreateWorkflowVersionRequest {
|
|
|
97
97
|
onFailureTask?: CreateTaskOpts | undefined;
|
|
98
98
|
/** (optional) the sticky strategy for assigning steps to workers */
|
|
99
99
|
sticky?: StickyStrategy | undefined;
|
|
100
|
+
/** (optional) the default priority for the workflow */
|
|
101
|
+
defaultPriority?: number | undefined;
|
|
100
102
|
}
|
|
101
103
|
export interface Concurrency {
|
|
102
104
|
/** (required) the expression to use for concurrency */
|
package/protoc/v1/workflows.js
CHANGED
|
@@ -758,6 +758,7 @@ function createBaseCreateWorkflowVersionRequest() {
|
|
|
758
758
|
cronInput: undefined,
|
|
759
759
|
onFailureTask: undefined,
|
|
760
760
|
sticky: undefined,
|
|
761
|
+
defaultPriority: undefined,
|
|
761
762
|
};
|
|
762
763
|
}
|
|
763
764
|
exports.CreateWorkflowVersionRequest = {
|
|
@@ -792,6 +793,9 @@ exports.CreateWorkflowVersionRequest = {
|
|
|
792
793
|
if (message.sticky !== undefined) {
|
|
793
794
|
writer.uint32(80).int32(message.sticky);
|
|
794
795
|
}
|
|
796
|
+
if (message.defaultPriority !== undefined) {
|
|
797
|
+
writer.uint32(88).int32(message.defaultPriority);
|
|
798
|
+
}
|
|
795
799
|
return writer;
|
|
796
800
|
},
|
|
797
801
|
decode(input, length) {
|
|
@@ -871,6 +875,13 @@ exports.CreateWorkflowVersionRequest = {
|
|
|
871
875
|
message.sticky = reader.int32();
|
|
872
876
|
continue;
|
|
873
877
|
}
|
|
878
|
+
case 11: {
|
|
879
|
+
if (tag !== 88) {
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
message.defaultPriority = reader.int32();
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
874
885
|
}
|
|
875
886
|
if ((tag & 7) === 4 || tag === 0) {
|
|
876
887
|
break;
|
|
@@ -899,6 +910,9 @@ exports.CreateWorkflowVersionRequest = {
|
|
|
899
910
|
? exports.CreateTaskOpts.fromJSON(object.onFailureTask)
|
|
900
911
|
: undefined,
|
|
901
912
|
sticky: isSet(object.sticky) ? stickyStrategyFromJSON(object.sticky) : undefined,
|
|
913
|
+
defaultPriority: isSet(object.defaultPriority)
|
|
914
|
+
? globalThis.Number(object.defaultPriority)
|
|
915
|
+
: undefined,
|
|
902
916
|
};
|
|
903
917
|
},
|
|
904
918
|
toJSON(message) {
|
|
@@ -934,13 +948,16 @@ exports.CreateWorkflowVersionRequest = {
|
|
|
934
948
|
if (message.sticky !== undefined) {
|
|
935
949
|
obj.sticky = stickyStrategyToJSON(message.sticky);
|
|
936
950
|
}
|
|
951
|
+
if (message.defaultPriority !== undefined) {
|
|
952
|
+
obj.defaultPriority = Math.round(message.defaultPriority);
|
|
953
|
+
}
|
|
937
954
|
return obj;
|
|
938
955
|
},
|
|
939
956
|
create(base) {
|
|
940
957
|
return exports.CreateWorkflowVersionRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
941
958
|
},
|
|
942
959
|
fromPartial(object) {
|
|
943
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
960
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
944
961
|
const message = createBaseCreateWorkflowVersionRequest();
|
|
945
962
|
message.name = (_a = object.name) !== null && _a !== void 0 ? _a : '';
|
|
946
963
|
message.description = (_b = object.description) !== null && _b !== void 0 ? _b : '';
|
|
@@ -958,6 +975,7 @@ exports.CreateWorkflowVersionRequest = {
|
|
|
958
975
|
? exports.CreateTaskOpts.fromPartial(object.onFailureTask)
|
|
959
976
|
: undefined;
|
|
960
977
|
message.sticky = (_h = object.sticky) !== null && _h !== void 0 ? _h : undefined;
|
|
978
|
+
message.defaultPriority = (_j = object.defaultPriority) !== null && _j !== void 0 ? _j : undefined;
|
|
961
979
|
return message;
|
|
962
980
|
},
|
|
963
981
|
};
|
|
@@ -195,6 +195,8 @@ export interface ScheduleWorkflowRequest {
|
|
|
195
195
|
childKey?: string | undefined;
|
|
196
196
|
/** (optional) the additional metadata for the workflow */
|
|
197
197
|
additionalMetadata?: string | undefined;
|
|
198
|
+
/** (optional) the priority of the workflow */
|
|
199
|
+
priority: number;
|
|
198
200
|
}
|
|
199
201
|
/** ScheduledWorkflow represents a scheduled workflow. */
|
|
200
202
|
export interface ScheduledWorkflow {
|
|
@@ -1409,6 +1409,7 @@ function createBaseScheduleWorkflowRequest() {
|
|
|
1409
1409
|
childIndex: undefined,
|
|
1410
1410
|
childKey: undefined,
|
|
1411
1411
|
additionalMetadata: undefined,
|
|
1412
|
+
priority: 0,
|
|
1412
1413
|
};
|
|
1413
1414
|
}
|
|
1414
1415
|
exports.ScheduleWorkflowRequest = {
|
|
@@ -1437,6 +1438,9 @@ exports.ScheduleWorkflowRequest = {
|
|
|
1437
1438
|
if (message.additionalMetadata !== undefined) {
|
|
1438
1439
|
writer.uint32(66).string(message.additionalMetadata);
|
|
1439
1440
|
}
|
|
1441
|
+
if (message.priority !== 0) {
|
|
1442
|
+
writer.uint32(72).int32(message.priority);
|
|
1443
|
+
}
|
|
1440
1444
|
return writer;
|
|
1441
1445
|
},
|
|
1442
1446
|
decode(input, length) {
|
|
@@ -1502,6 +1506,13 @@ exports.ScheduleWorkflowRequest = {
|
|
|
1502
1506
|
message.additionalMetadata = reader.string();
|
|
1503
1507
|
continue;
|
|
1504
1508
|
}
|
|
1509
|
+
case 9: {
|
|
1510
|
+
if (tag !== 72) {
|
|
1511
|
+
break;
|
|
1512
|
+
}
|
|
1513
|
+
message.priority = reader.int32();
|
|
1514
|
+
continue;
|
|
1515
|
+
}
|
|
1505
1516
|
}
|
|
1506
1517
|
if ((tag & 7) === 4 || tag === 0) {
|
|
1507
1518
|
break;
|
|
@@ -1526,6 +1537,7 @@ exports.ScheduleWorkflowRequest = {
|
|
|
1526
1537
|
additionalMetadata: isSet(object.additionalMetadata)
|
|
1527
1538
|
? globalThis.String(object.additionalMetadata)
|
|
1528
1539
|
: undefined,
|
|
1540
|
+
priority: isSet(object.priority) ? globalThis.Number(object.priority) : 0,
|
|
1529
1541
|
};
|
|
1530
1542
|
},
|
|
1531
1543
|
toJSON(message) {
|
|
@@ -1555,13 +1567,16 @@ exports.ScheduleWorkflowRequest = {
|
|
|
1555
1567
|
if (message.additionalMetadata !== undefined) {
|
|
1556
1568
|
obj.additionalMetadata = message.additionalMetadata;
|
|
1557
1569
|
}
|
|
1570
|
+
if (message.priority !== 0) {
|
|
1571
|
+
obj.priority = Math.round(message.priority);
|
|
1572
|
+
}
|
|
1558
1573
|
return obj;
|
|
1559
1574
|
},
|
|
1560
1575
|
create(base) {
|
|
1561
1576
|
return exports.ScheduleWorkflowRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
1562
1577
|
},
|
|
1563
1578
|
fromPartial(object) {
|
|
1564
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1579
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
1565
1580
|
const message = createBaseScheduleWorkflowRequest();
|
|
1566
1581
|
message.name = (_a = object.name) !== null && _a !== void 0 ? _a : '';
|
|
1567
1582
|
message.schedules = ((_b = object.schedules) === null || _b === void 0 ? void 0 : _b.map((e) => e)) || [];
|
|
@@ -1571,6 +1586,7 @@ exports.ScheduleWorkflowRequest = {
|
|
|
1571
1586
|
message.childIndex = (_f = object.childIndex) !== null && _f !== void 0 ? _f : undefined;
|
|
1572
1587
|
message.childKey = (_g = object.childKey) !== null && _g !== void 0 ? _g : undefined;
|
|
1573
1588
|
message.additionalMetadata = (_h = object.additionalMetadata) !== null && _h !== void 0 ? _h : undefined;
|
|
1589
|
+
message.priority = (_j = object.priority) !== null && _j !== void 0 ? _j : 0;
|
|
1574
1590
|
return message;
|
|
1575
1591
|
},
|
|
1576
1592
|
};
|
package/step.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ import WorkflowRunRef from './util/workflow-run-ref';
|
|
|
8
8
|
import { V0Worker } from './clients/worker';
|
|
9
9
|
import { WorkerLabels } from './clients/dispatcher/dispatcher-client';
|
|
10
10
|
import { CreateStepRateLimit, RateLimitDuration, WorkerLabelComparator } from './protoc/workflows';
|
|
11
|
-
import { CreateWorkflowTaskOpts } from './v1
|
|
12
|
-
import { TaskWorkflowDeclaration, BaseWorkflowDeclaration as WorkflowV1 } from './v1/declaration';
|
|
11
|
+
import { CreateWorkflowTaskOpts, Priority } from './v1';
|
|
12
|
+
import { RunOpts, TaskWorkflowDeclaration, BaseWorkflowDeclaration as WorkflowV1 } from './v1/declaration';
|
|
13
13
|
import { Conditions } from './v1/conditions';
|
|
14
14
|
import { Duration } from './v1/client/duration';
|
|
15
15
|
import { JsonObject, JsonValue, OutputType } from './v1/types';
|
|
@@ -155,6 +155,10 @@ export type NextStep = {
|
|
|
155
155
|
[key: string]: JsonValue;
|
|
156
156
|
};
|
|
157
157
|
type TriggerData = Record<string, Record<string, any>>;
|
|
158
|
+
type ChildRunOpts = RunOpts & {
|
|
159
|
+
key?: string;
|
|
160
|
+
sticky?: boolean;
|
|
161
|
+
};
|
|
158
162
|
interface ContextData<T, K> {
|
|
159
163
|
input: T;
|
|
160
164
|
triggers: TriggerData;
|
|
@@ -314,11 +318,7 @@ export declare class Context<T, K = {}> {
|
|
|
314
318
|
bulkRunNoWaitChildren<Q extends JsonObject = any, P extends JsonObject = any>(children: Array<{
|
|
315
319
|
workflow: string | Workflow | WorkflowV1<Q, P>;
|
|
316
320
|
input: Q;
|
|
317
|
-
options?:
|
|
318
|
-
key?: string;
|
|
319
|
-
sticky?: boolean;
|
|
320
|
-
additionalMetadata?: Record<string, string>;
|
|
321
|
-
};
|
|
321
|
+
options?: ChildRunOpts;
|
|
322
322
|
}>): Promise<WorkflowRunRef<P>[]>;
|
|
323
323
|
/**
|
|
324
324
|
* Runs multiple children workflows in parallel and waits for all results.
|
|
@@ -328,11 +328,7 @@ export declare class Context<T, K = {}> {
|
|
|
328
328
|
bulkRunChildren<Q extends JsonObject = any, P extends JsonObject = any>(children: Array<{
|
|
329
329
|
workflow: string | Workflow | WorkflowV1<Q, P>;
|
|
330
330
|
input: Q;
|
|
331
|
-
options?:
|
|
332
|
-
key?: string;
|
|
333
|
-
sticky?: boolean;
|
|
334
|
-
additionalMetadata?: Record<string, string>;
|
|
335
|
-
};
|
|
331
|
+
options?: ChildRunOpts;
|
|
336
332
|
}>): Promise<P[]>;
|
|
337
333
|
/**
|
|
338
334
|
* Spawns multiple workflows.
|
|
@@ -344,38 +340,26 @@ export declare class Context<T, K = {}> {
|
|
|
344
340
|
spawnWorkflows<Q extends JsonObject = any, P extends JsonObject = any>(workflows: Array<{
|
|
345
341
|
workflow: string | Workflow | WorkflowV1<Q, P>;
|
|
346
342
|
input: Q;
|
|
347
|
-
options?:
|
|
348
|
-
key?: string;
|
|
349
|
-
sticky?: boolean;
|
|
350
|
-
additionalMetadata?: Record<string, string>;
|
|
351
|
-
};
|
|
343
|
+
options?: ChildRunOpts;
|
|
352
344
|
}>): Promise<WorkflowRunRef<P>[]>;
|
|
353
345
|
/**
|
|
354
346
|
* Runs a new workflow and waits for its result.
|
|
355
347
|
*
|
|
356
348
|
* @param workflow - The workflow to run (name, Workflow instance, or WorkflowV1 instance).
|
|
357
349
|
* @param input - The input data for the workflow.
|
|
358
|
-
* @param
|
|
350
|
+
* @param options - An options object containing key, sticky, priority, and additionalMetadata.
|
|
359
351
|
* @returns The result of the workflow.
|
|
360
352
|
*/
|
|
361
|
-
runChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q,
|
|
362
|
-
key?: string;
|
|
363
|
-
sticky?: boolean;
|
|
364
|
-
additionalMetadata?: Record<string, string>;
|
|
365
|
-
}): Promise<P>;
|
|
353
|
+
runChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q, options?: ChildRunOpts): Promise<P>;
|
|
366
354
|
/**
|
|
367
355
|
* Enqueues a new workflow without waiting for its result.
|
|
368
356
|
*
|
|
369
357
|
* @param workflow - The workflow to enqueue (name, Workflow instance, or WorkflowV1 instance).
|
|
370
358
|
* @param input - The input data for the workflow.
|
|
371
|
-
* @param
|
|
359
|
+
* @param options - An options object containing key, sticky, priority, and additionalMetadata.
|
|
372
360
|
* @returns A reference to the spawned workflow run.
|
|
373
361
|
*/
|
|
374
|
-
runNoWaitChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q,
|
|
375
|
-
key?: string;
|
|
376
|
-
sticky?: boolean;
|
|
377
|
-
additionalMetadata?: Record<string, string>;
|
|
378
|
-
}): WorkflowRunRef<P>;
|
|
362
|
+
runNoWaitChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, options?: ChildRunOpts): WorkflowRunRef<P>;
|
|
379
363
|
/**
|
|
380
364
|
* Spawns a new workflow.
|
|
381
365
|
*
|
|
@@ -385,11 +369,7 @@ export declare class Context<T, K = {}> {
|
|
|
385
369
|
* @returns A reference to the spawned workflow run.
|
|
386
370
|
* @deprecated Use runChild or runNoWaitChild instead.
|
|
387
371
|
*/
|
|
388
|
-
spawnWorkflow<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q, options?:
|
|
389
|
-
key?: string;
|
|
390
|
-
sticky?: boolean;
|
|
391
|
-
additionalMetadata?: Record<string, string>;
|
|
392
|
-
}): WorkflowRunRef<P>;
|
|
372
|
+
spawnWorkflow<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q, options?: ChildRunOpts): WorkflowRunRef<P>;
|
|
393
373
|
/**
|
|
394
374
|
* Retrieves additional metadata associated with the current workflow run.
|
|
395
375
|
* @returns A record of metadata key-value pairs.
|
|
@@ -410,6 +390,7 @@ export declare class Context<T, K = {}> {
|
|
|
410
390
|
* @returns The parent workflow run ID, or undefined if not a child workflow.
|
|
411
391
|
*/
|
|
412
392
|
parentWorkflowRunId(): string | undefined;
|
|
393
|
+
priority(): Priority | undefined;
|
|
413
394
|
}
|
|
414
395
|
export declare class DurableContext<T, K = {}> extends Context<T, K> {
|
|
415
396
|
waitKey: number;
|
package/step.js
CHANGED
|
@@ -53,6 +53,7 @@ const hatchet_error_1 = __importDefault(require("./util/errors/hatchet-error"));
|
|
|
53
53
|
const z = __importStar(require("zod"));
|
|
54
54
|
const parse_1 = require("./util/parse");
|
|
55
55
|
const workflows_1 = require("./protoc/workflows");
|
|
56
|
+
const v1_1 = require("./v1");
|
|
56
57
|
const declaration_1 = require("./v1/declaration");
|
|
57
58
|
const conditions_1 = require("./v1/conditions");
|
|
58
59
|
const condition_1 = require("./protoc/v1/shared/condition");
|
|
@@ -386,28 +387,15 @@ class Context {
|
|
|
386
387
|
workflowName = workflow.id;
|
|
387
388
|
}
|
|
388
389
|
const name = this.client.config.namespace + workflowName;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
let metadata;
|
|
392
|
-
if (options) {
|
|
393
|
-
key = options.key;
|
|
394
|
-
sticky = options.sticky;
|
|
395
|
-
metadata = options.additionalMetadata;
|
|
396
|
-
}
|
|
390
|
+
const opts = options || {};
|
|
391
|
+
const { sticky } = opts;
|
|
397
392
|
if (sticky && !this.worker.hasWorkflow(name)) {
|
|
398
393
|
throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${name} is not registered on the worker`);
|
|
399
394
|
}
|
|
400
395
|
const resp = {
|
|
401
396
|
workflowName: name,
|
|
402
397
|
input,
|
|
403
|
-
options: {
|
|
404
|
-
parentId: workflowRunId,
|
|
405
|
-
parentStepRunId: stepRunId,
|
|
406
|
-
childKey: key,
|
|
407
|
-
childIndex: this.spawnIndex,
|
|
408
|
-
desiredWorkerId: sticky ? this.worker.id() : undefined,
|
|
409
|
-
additionalMetadata: metadata,
|
|
410
|
-
},
|
|
398
|
+
options: Object.assign(Object.assign({}, opts), { parentId: workflowRunId, parentStepRunId: stepRunId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined }),
|
|
411
399
|
};
|
|
412
400
|
this.spawnIndex += 1;
|
|
413
401
|
return resp;
|
|
@@ -441,12 +429,12 @@ class Context {
|
|
|
441
429
|
*
|
|
442
430
|
* @param workflow - The workflow to run (name, Workflow instance, or WorkflowV1 instance).
|
|
443
431
|
* @param input - The input data for the workflow.
|
|
444
|
-
* @param
|
|
432
|
+
* @param options - An options object containing key, sticky, priority, and additionalMetadata.
|
|
445
433
|
* @returns The result of the workflow.
|
|
446
434
|
*/
|
|
447
|
-
runChild(workflow, input,
|
|
435
|
+
runChild(workflow, input, options) {
|
|
448
436
|
return __awaiter(this, void 0, void 0, function* () {
|
|
449
|
-
const run = yield this.spawnWorkflow(workflow, input,
|
|
437
|
+
const run = yield this.spawnWorkflow(workflow, input, options);
|
|
450
438
|
return run.output;
|
|
451
439
|
});
|
|
452
440
|
}
|
|
@@ -455,11 +443,11 @@ class Context {
|
|
|
455
443
|
*
|
|
456
444
|
* @param workflow - The workflow to enqueue (name, Workflow instance, or WorkflowV1 instance).
|
|
457
445
|
* @param input - The input data for the workflow.
|
|
458
|
-
* @param
|
|
446
|
+
* @param options - An options object containing key, sticky, priority, and additionalMetadata.
|
|
459
447
|
* @returns A reference to the spawned workflow run.
|
|
460
448
|
*/
|
|
461
|
-
runNoWaitChild(workflow, input,
|
|
462
|
-
return this.spawnWorkflow(workflow, input,
|
|
449
|
+
runNoWaitChild(workflow, input, options) {
|
|
450
|
+
return this.spawnWorkflow(workflow, input, options);
|
|
463
451
|
}
|
|
464
452
|
/**
|
|
465
453
|
* Spawns a new workflow.
|
|
@@ -480,30 +468,13 @@ class Context {
|
|
|
480
468
|
workflowName = workflow.id;
|
|
481
469
|
}
|
|
482
470
|
const name = this.client.config.namespace + workflowName;
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
let metadata;
|
|
486
|
-
if (typeof options === 'string') {
|
|
487
|
-
this.logger.warn('Using key param is deprecated and will be removed in a future release. Use options.key instead.');
|
|
488
|
-
key = options;
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
key = options === null || options === void 0 ? void 0 : options.key;
|
|
492
|
-
sticky = options === null || options === void 0 ? void 0 : options.sticky;
|
|
493
|
-
metadata = options === null || options === void 0 ? void 0 : options.additionalMetadata;
|
|
494
|
-
}
|
|
471
|
+
const opts = options || {};
|
|
472
|
+
const { sticky } = opts;
|
|
495
473
|
if (sticky && !this.worker.hasWorkflow(name)) {
|
|
496
474
|
throw new hatchet_error_1.default(`cannot run with sticky: workflow ${name} is not registered on the worker`);
|
|
497
475
|
}
|
|
498
476
|
try {
|
|
499
|
-
const resp = this.client.admin.runWorkflow(name, input, {
|
|
500
|
-
parentId: workflowRunId,
|
|
501
|
-
parentStepRunId: stepRunId,
|
|
502
|
-
childKey: key,
|
|
503
|
-
childIndex: this.spawnIndex,
|
|
504
|
-
desiredWorkerId: sticky ? this.worker.id() : undefined,
|
|
505
|
-
additionalMetadata: metadata,
|
|
506
|
-
});
|
|
477
|
+
const resp = this.client.admin.runWorkflow(name, input, Object.assign({ parentId: workflowRunId, parentStepRunId: stepRunId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined }, opts));
|
|
507
478
|
this.spawnIndex += 1;
|
|
508
479
|
if (workflow instanceof declaration_1.TaskWorkflowDeclaration) {
|
|
509
480
|
resp._standalone_task_name = workflow._standalone_task_name;
|
|
@@ -547,6 +518,18 @@ class Context {
|
|
|
547
518
|
parentWorkflowRunId() {
|
|
548
519
|
return this.action.parentWorkflowRunId;
|
|
549
520
|
}
|
|
521
|
+
priority() {
|
|
522
|
+
switch (this.action.priority) {
|
|
523
|
+
case 1:
|
|
524
|
+
return v1_1.Priority.LOW;
|
|
525
|
+
case 2:
|
|
526
|
+
return v1_1.Priority.MEDIUM;
|
|
527
|
+
case 3:
|
|
528
|
+
return v1_1.Priority.HIGH;
|
|
529
|
+
default:
|
|
530
|
+
return undefined;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
550
533
|
}
|
|
551
534
|
exports.Context = Context;
|
|
552
535
|
class DurableContext extends Context {
|