@hatchet-dev/typescript-sdk 1.10.8 → 1.12.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 +38 -0
- package/clients/admin/admin-client.js +19 -6
- package/clients/dispatcher/action-listener.d.ts +6 -2
- package/clients/dispatcher/action-listener.js +2 -2
- package/clients/dispatcher/dispatcher-client.d.ts +8 -2
- package/clients/dispatcher/dispatcher-client.js +18 -4
- package/clients/event/event-client.d.ts +2 -2
- package/clients/event/event-client.js +4 -4
- package/clients/hatchet-client/hatchet-logger.js +2 -2
- package/clients/rest/generated/data-contracts.d.ts +13 -1
- package/clients/worker/worker.js +11 -11
- package/examples/webhooks.d.ts +1 -0
- package/examples/webhooks.js +45 -0
- package/package.json +1 -1
- package/protoc/dispatcher/dispatcher.d.ts +25 -25
- package/protoc/dispatcher/dispatcher.js +109 -95
- package/protoc/events/events.d.ts +4 -4
- package/protoc/events/events.js +20 -16
- package/protoc/v1/workflows.d.ts +7 -7
- package/protoc/workflows/workflows.d.ts +22 -22
- package/protoc/workflows/workflows.js +18 -18
- package/step.d.ts +1 -1
- package/step.js +19 -19
- package/util/workflow-run-ref.js +1 -1
- package/v1/client/admin.d.ts +30 -0
- package/v1/client/admin.js +21 -6
- package/v1/client/client.d.ts +8 -1
- package/v1/client/client.js +12 -1
- package/v1/client/features/metrics.d.ts +16 -5
- package/v1/client/features/metrics.js +13 -14
- package/v1/client/features/runs.d.ts +9 -1
- package/v1/client/features/runs.js +4 -2
- package/v1/client/features/webhooks.d.ts +28 -0
- package/v1/client/features/webhooks.js +97 -0
- package/v1/client/worker/context.d.ts +1 -1
- package/v1/client/worker/context.js +23 -23
- package/v1/client/worker/worker-internal.d.ts +2 -2
- package/v1/client/worker/worker-internal.js +25 -25
- package/v1/declaration.d.ts +2 -2
- package/v1/declaration.js +24 -10
- package/v1/parent-run-context-vars.d.ts +4 -1
- package/v1/parent-run-context-vars.js +1 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -19,6 +19,16 @@ export type WorkflowRun<T = object> = {
|
|
|
19
19
|
input: T;
|
|
20
20
|
options?: {
|
|
21
21
|
parentId?: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* (optional) the parent task external run id.
|
|
24
|
+
*
|
|
25
|
+
* This is the field understood by the workflows gRPC API.
|
|
26
|
+
*/
|
|
27
|
+
parentTaskRunExternalId?: string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use `parentTaskRunExternalId` instead.
|
|
30
|
+
* Kept for backward compatibility; will be mapped to `parentTaskRunExternalId`.
|
|
31
|
+
*/
|
|
22
32
|
parentStepRunId?: string | undefined;
|
|
23
33
|
childIndex?: number | undefined;
|
|
24
34
|
childKey?: string | undefined;
|
|
@@ -65,6 +75,14 @@ export declare class AdminClient {
|
|
|
65
75
|
*/
|
|
66
76
|
run_workflow<T = object>(workflowName: string, input: T, options?: {
|
|
67
77
|
parentId?: string | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* (optional) the parent task external run id.
|
|
80
|
+
*/
|
|
81
|
+
parentTaskRunExternalId?: string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated Use `parentTaskRunExternalId` instead.
|
|
84
|
+
* Kept for backward compatibility; will be mapped to `parentTaskRunExternalId`.
|
|
85
|
+
*/
|
|
68
86
|
parentStepRunId?: string | undefined;
|
|
69
87
|
childIndex?: number | undefined;
|
|
70
88
|
childKey?: string | undefined;
|
|
@@ -80,6 +98,16 @@ export declare class AdminClient {
|
|
|
80
98
|
*/
|
|
81
99
|
runWorkflow<Q = object, P = object>(workflowName: string, input: Q, options?: {
|
|
82
100
|
parentId?: string | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* (optional) the parent task external run id.
|
|
103
|
+
*
|
|
104
|
+
* This is the field understood by the workflows gRPC API.
|
|
105
|
+
*/
|
|
106
|
+
parentTaskRunExternalId?: string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated Use `parentTaskRunExternalId` instead.
|
|
109
|
+
* Kept for backward compatibility; will be mapped to `parentTaskRunExternalId`.
|
|
110
|
+
*/
|
|
83
111
|
parentStepRunId?: string | undefined;
|
|
84
112
|
childIndex?: number | undefined;
|
|
85
113
|
childKey?: string | undefined;
|
|
@@ -98,6 +126,16 @@ export declare class AdminClient {
|
|
|
98
126
|
input: Q;
|
|
99
127
|
options?: {
|
|
100
128
|
parentId?: string | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* (optional) the parent task external run id.
|
|
131
|
+
*
|
|
132
|
+
* This is the field understood by the workflows gRPC API.
|
|
133
|
+
*/
|
|
134
|
+
parentTaskRunExternalId?: string | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* @deprecated Use `parentTaskRunExternalId` instead.
|
|
137
|
+
* Kept for backward compatibility; will be mapped to `parentTaskRunExternalId`.
|
|
138
|
+
*/
|
|
101
139
|
parentStepRunId?: string | undefined;
|
|
102
140
|
childIndex?: number | undefined;
|
|
103
141
|
childKey?: string | undefined;
|
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -120,9 +131,11 @@ class AdminClient {
|
|
|
120
131
|
const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
|
|
121
132
|
try {
|
|
122
133
|
const inputStr = JSON.stringify(input);
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
134
|
+
const opts = options !== null && options !== void 0 ? options : {};
|
|
135
|
+
const { additionalMetadata, parentStepRunId, parentTaskRunExternalId } = opts, rest = __rest(opts, ["additionalMetadata", "parentStepRunId", "parentTaskRunExternalId"]);
|
|
136
|
+
const resp = this.client.triggerWorkflow(Object.assign(Object.assign({ name: computedName, input: inputStr }, rest), {
|
|
137
|
+
// API expects `parentTaskRunExternalId`; accept the old name as an alias.
|
|
138
|
+
parentTaskRunExternalId: parentTaskRunExternalId !== null && parentTaskRunExternalId !== void 0 ? parentTaskRunExternalId : parentStepRunId, additionalMetadata: additionalMetadata ? JSON.stringify(additionalMetadata) : undefined, priority: opts.priority }));
|
|
126
139
|
return new workflow_run_ref_1.default(resp, this.listenerClient, this.workflows, options === null || options === void 0 ? void 0 : options.parentId);
|
|
127
140
|
}
|
|
128
141
|
catch (e) {
|
|
@@ -140,9 +153,9 @@ class AdminClient {
|
|
|
140
153
|
const workflowRequests = workflowRuns.map(({ workflowName, input, options }) => {
|
|
141
154
|
const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
|
|
142
155
|
const inputStr = JSON.stringify(input);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
156
|
+
const opts = options !== null && options !== void 0 ? options : {};
|
|
157
|
+
const { additionalMetadata, parentStepRunId, parentTaskRunExternalId } = opts, rest = __rest(opts, ["additionalMetadata", "parentStepRunId", "parentTaskRunExternalId"]);
|
|
158
|
+
return Object.assign(Object.assign({ name: computedName, input: inputStr }, rest), { parentTaskRunExternalId: parentTaskRunExternalId !== null && parentTaskRunExternalId !== void 0 ? parentTaskRunExternalId : parentStepRunId, additionalMetadata: additionalMetadata ? JSON.stringify(additionalMetadata) : undefined });
|
|
146
159
|
});
|
|
147
160
|
try {
|
|
148
161
|
// Call the bulk trigger workflow method
|
|
@@ -7,8 +7,12 @@ declare enum ListenStrategy {
|
|
|
7
7
|
LISTEN_STRATEGY_V1 = 1,
|
|
8
8
|
LISTEN_STRATEGY_V2 = 2
|
|
9
9
|
}
|
|
10
|
-
export
|
|
11
|
-
|
|
10
|
+
export type Action = AssignedAction & {
|
|
11
|
+
/** @deprecated use taskRunId */
|
|
12
|
+
stepRunId?: string;
|
|
13
|
+
/** @deprecated use taskId */
|
|
14
|
+
stepId?: string;
|
|
15
|
+
};
|
|
12
16
|
export type ActionKey = string;
|
|
13
17
|
export declare function createActionKey(action: Action): ActionKey;
|
|
14
18
|
export declare class ActionListener {
|
|
@@ -55,7 +55,7 @@ function createActionKey(action) {
|
|
|
55
55
|
case dispatcher_1.ActionType.CANCEL_STEP_RUN:
|
|
56
56
|
case dispatcher_1.ActionType.START_STEP_RUN:
|
|
57
57
|
case dispatcher_1.ActionType.UNRECOGNIZED:
|
|
58
|
-
return `${action.
|
|
58
|
+
return `${action.taskRunExternalId}/${action.retryCount}`;
|
|
59
59
|
default:
|
|
60
60
|
// eslint-disable-next-line no-case-declarations
|
|
61
61
|
const exhaustivenessCheck = action.actionType;
|
|
@@ -84,7 +84,7 @@ class ActionListener {
|
|
|
84
84
|
_c = listenClient_1_1.value;
|
|
85
85
|
_d = false;
|
|
86
86
|
const assignedAction = _c;
|
|
87
|
-
const action = Object.assign({}, assignedAction);
|
|
87
|
+
const action = Object.assign(Object.assign({}, assignedAction), { stepRunId: assignedAction.taskRunExternalId, stepId: assignedAction.taskId });
|
|
88
88
|
yield yield __await(action);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -11,6 +11,12 @@ interface GetActionListenerOptions {
|
|
|
11
11
|
maxRuns?: number;
|
|
12
12
|
labels: Record<string, string | number | undefined>;
|
|
13
13
|
}
|
|
14
|
+
type StepActionEventInput = StepActionEvent & {
|
|
15
|
+
/** @deprecated use taskId */
|
|
16
|
+
stepId?: string;
|
|
17
|
+
/** @deprecated use taskRunId */
|
|
18
|
+
stepRunId?: string;
|
|
19
|
+
};
|
|
14
20
|
export declare class DispatcherClient {
|
|
15
21
|
config: ClientConfig;
|
|
16
22
|
client: PbDispatcherClient;
|
|
@@ -18,10 +24,10 @@ export declare class DispatcherClient {
|
|
|
18
24
|
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
|
|
19
25
|
getRuntimeInfo(): RuntimeInfo;
|
|
20
26
|
getActionListener(options: GetActionListenerOptions): Promise<ActionListener>;
|
|
21
|
-
sendStepActionEvent(in_:
|
|
27
|
+
sendStepActionEvent(in_: StepActionEventInput): Promise<import("../../protoc/dispatcher").ActionEventResponse>;
|
|
22
28
|
sendGroupKeyActionEvent(in_: GroupKeyActionEvent): Promise<import("../../protoc/dispatcher").ActionEventResponse>;
|
|
23
29
|
putOverridesData(in_: DeepPartial<OverridesData>): Promise<void | import("../../protoc/dispatcher").OverridesDataResponse>;
|
|
24
|
-
refreshTimeout(incrementTimeoutBy: string,
|
|
30
|
+
refreshTimeout(incrementTimeoutBy: string, taskRunExternalId: string): Promise<import("../../protoc/dispatcher").RefreshTimeoutResponse>;
|
|
25
31
|
upsertWorkerLabels(workerId: string, labels: WorkerLabels): Promise<import("../../protoc/dispatcher").UpsertWorkerLabelsResponse>;
|
|
26
32
|
}
|
|
27
33
|
export {};
|
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -35,14 +46,17 @@ class DispatcherClient {
|
|
|
35
46
|
getActionListener(options) {
|
|
36
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
48
|
// Register the worker
|
|
38
|
-
const
|
|
49
|
+
const { maxRuns } = options, rest = __rest(options, ["maxRuns"]);
|
|
50
|
+
const registration = yield this.client.register(Object.assign(Object.assign({}, rest), { slots: maxRuns, labels: options.labels ? mapLabels(options.labels) : undefined, runtimeInfo: this.getRuntimeInfo() }));
|
|
39
51
|
return new action_listener_1.ActionListener(this, registration.workerId);
|
|
40
52
|
});
|
|
41
53
|
}
|
|
42
54
|
sendStepActionEvent(in_) {
|
|
43
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const { taskId, taskRunExternalId } = in_, rest = __rest(in_, ["taskId", "taskRunExternalId"]);
|
|
57
|
+
const event = Object.assign(Object.assign({}, rest), { taskId: taskId !== null && taskId !== void 0 ? taskId : '', taskRunExternalId: taskRunExternalId !== null && taskRunExternalId !== void 0 ? taskRunExternalId : '' });
|
|
44
58
|
try {
|
|
45
|
-
return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.sendStepActionEvent(
|
|
59
|
+
return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.sendStepActionEvent(event); }), this.logger);
|
|
46
60
|
}
|
|
47
61
|
catch (e) {
|
|
48
62
|
throw new hatchet_error_1.default(e.message);
|
|
@@ -66,11 +80,11 @@ class DispatcherClient {
|
|
|
66
80
|
});
|
|
67
81
|
});
|
|
68
82
|
}
|
|
69
|
-
refreshTimeout(incrementTimeoutBy,
|
|
83
|
+
refreshTimeout(incrementTimeoutBy, taskRunExternalId) {
|
|
70
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
85
|
try {
|
|
72
86
|
return this.client.refreshTimeout({
|
|
73
|
-
|
|
87
|
+
taskRunExternalId,
|
|
74
88
|
incrementTimeoutBy,
|
|
75
89
|
});
|
|
76
90
|
}
|
|
@@ -32,7 +32,7 @@ export declare class EventClient {
|
|
|
32
32
|
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory, hatchetClient: LegacyHatchetClient);
|
|
33
33
|
push<T>(type: string, input: T, options?: PushEventOptions): Promise<import("../../protoc/events/events").Event>;
|
|
34
34
|
bulkPush<T>(type: string, inputs: EventWithMetadata<T>[], options?: PushEventOptions): Promise<import("../../protoc/events/events").Events>;
|
|
35
|
-
putLog(
|
|
36
|
-
putStream(
|
|
35
|
+
putLog(taskRunExternalId: string, log: string, level?: LogLevel, taskRetryCount?: number, metadata?: Record<string, any>): Promise<void>;
|
|
36
|
+
putStream(taskRunExternalId: string, data: string | Uint8Array, index: number | undefined): Promise<void>;
|
|
37
37
|
list(opts?: Parameters<typeof this.api.v1EventList>[1]): Promise<import("../rest/generated/data-contracts").V1EventList>;
|
|
38
38
|
}
|
|
@@ -87,7 +87,7 @@ class EventClient {
|
|
|
87
87
|
throw new hatchet_error_1.default(e.message);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
putLog(
|
|
90
|
+
putLog(taskRunExternalId, log, level, taskRetryCount, metadata) {
|
|
91
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
92
|
const createdAt = new Date();
|
|
93
93
|
if (log.length > 1000) {
|
|
@@ -97,7 +97,7 @@ class EventClient {
|
|
|
97
97
|
// fire and forget the log
|
|
98
98
|
yield this.client
|
|
99
99
|
.putLog({
|
|
100
|
-
|
|
100
|
+
taskRunExternalId,
|
|
101
101
|
createdAt,
|
|
102
102
|
message: log,
|
|
103
103
|
level: level || LogLevel.INFO,
|
|
@@ -110,7 +110,7 @@ class EventClient {
|
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
putStream(
|
|
113
|
+
putStream(taskRunExternalId, data, index) {
|
|
114
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
115
|
const createdAt = new Date();
|
|
116
116
|
let dataBytes;
|
|
@@ -125,7 +125,7 @@ class EventClient {
|
|
|
125
125
|
}
|
|
126
126
|
(0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () {
|
|
127
127
|
return this.client.putStreamEvent({
|
|
128
|
-
|
|
128
|
+
taskRunExternalId,
|
|
129
129
|
createdAt,
|
|
130
130
|
message: dataBytes,
|
|
131
131
|
eventIndex: index,
|
|
@@ -64,12 +64,12 @@ class HatchetLogger {
|
|
|
64
64
|
}
|
|
65
65
|
warn(message, error) {
|
|
66
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
yield this.log('WARN', `${message} ${error}
|
|
67
|
+
yield this.log('WARN', error ? `${message} ${error}` : message, '93');
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
error(message, error) {
|
|
71
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
yield this.log('ERROR', `${message} ${error}
|
|
72
|
+
yield this.log('ERROR', error ? `${message} ${error}` : message, '91');
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
util(key, message, extra) {
|
|
@@ -807,6 +807,10 @@ export interface V1Webhook {
|
|
|
807
807
|
sourceName: V1WebhookSourceName;
|
|
808
808
|
/** The CEL expression to use for the event key. This is used to create the event key from the webhook payload. */
|
|
809
809
|
eventKeyExpression: string;
|
|
810
|
+
/** The CEL expression to use for the scope. This is used to filter the correct workflow to trigger. */
|
|
811
|
+
scopeExpression?: string;
|
|
812
|
+
/** The static payload to use for the webhook. This is used to send a static payload with the webhook. */
|
|
813
|
+
staticPayload?: object;
|
|
810
814
|
/** The type of authentication to use for the webhook */
|
|
811
815
|
authType: V1WebhookAuthType;
|
|
812
816
|
}
|
|
@@ -821,6 +825,10 @@ export interface V1CreateWebhookRequestBase {
|
|
|
821
825
|
name: string;
|
|
822
826
|
/** The CEL expression to use for the event key. This is used to create the event key from the webhook payload. */
|
|
823
827
|
eventKeyExpression: string;
|
|
828
|
+
/** The CEL expression to use for the scope. This is used to filter the correct workflow to trigger. */
|
|
829
|
+
scopeExpression?: string;
|
|
830
|
+
/** The static payload to use for the webhook. This is used to send a static payload with the webhook. */
|
|
831
|
+
staticPayload?: object;
|
|
824
832
|
}
|
|
825
833
|
export interface V1WebhookBasicAuth {
|
|
826
834
|
/** The username for basic auth */
|
|
@@ -862,7 +870,11 @@ export type V1CreateWebhookRequestHMAC = V1CreateWebhookRequestBase & {
|
|
|
862
870
|
export type V1CreateWebhookRequest = V1CreateWebhookRequestBasicAuth | V1CreateWebhookRequestAPIKey | V1CreateWebhookRequestHMAC;
|
|
863
871
|
export interface V1UpdateWebhookRequest {
|
|
864
872
|
/** The CEL expression to use for the event key. This is used to create the event key from the webhook payload. */
|
|
865
|
-
eventKeyExpression
|
|
873
|
+
eventKeyExpression?: string;
|
|
874
|
+
/** The CEL expression to use for the scope. This is used to filter the correct workflow to trigger. */
|
|
875
|
+
scopeExpression?: string;
|
|
876
|
+
/** The static payload to use for the webhook. This is used to send a static payload with the webhook. */
|
|
877
|
+
staticPayload?: object;
|
|
866
878
|
}
|
|
867
879
|
export interface V1CELDebugRequest {
|
|
868
880
|
/** The CEL expression to evaluate */
|
package/clients/worker/worker.js
CHANGED
|
@@ -187,7 +187,7 @@ class V0Worker {
|
|
|
187
187
|
return step(context);
|
|
188
188
|
});
|
|
189
189
|
const success = (result) => __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
this.logger.info(`Task run ${action.
|
|
190
|
+
this.logger.info(`Task run ${action.taskRunExternalId} succeeded`);
|
|
191
191
|
try {
|
|
192
192
|
// Send the action event to the dispatcher
|
|
193
193
|
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, false, result || null, action.retryCount);
|
|
@@ -212,7 +212,7 @@ class V0Worker {
|
|
|
212
212
|
}
|
|
213
213
|
});
|
|
214
214
|
const failure = (error) => __awaiter(this, void 0, void 0, function* () {
|
|
215
|
-
this.logger.error(`Task run ${action.
|
|
215
|
+
this.logger.error(`Task run ${action.taskRunExternalId} failed: ${error.message}`);
|
|
216
216
|
if (error.stack) {
|
|
217
217
|
this.logger.error(error.stack);
|
|
218
218
|
}
|
|
@@ -257,10 +257,10 @@ class V0Worker {
|
|
|
257
257
|
catch (e) {
|
|
258
258
|
const message = (e === null || e === void 0 ? void 0 : e.message) || String(e);
|
|
259
259
|
if (message.includes('Cancelled')) {
|
|
260
|
-
this.logger.debug(`Task run ${action.
|
|
260
|
+
this.logger.debug(`Task run ${action.taskRunExternalId} was cancelled`);
|
|
261
261
|
}
|
|
262
262
|
else {
|
|
263
|
-
this.logger.error(`Could not wait for task run ${action.
|
|
263
|
+
this.logger.error(`Could not wait for task run ${action.taskRunExternalId} to finish. ` +
|
|
264
264
|
`See https://docs.hatchet.run/home/cancellation for best practices on handling cancellation: `, e);
|
|
265
265
|
}
|
|
266
266
|
}
|
|
@@ -291,7 +291,7 @@ class V0Worker {
|
|
|
291
291
|
return step(context);
|
|
292
292
|
});
|
|
293
293
|
const success = (result) => {
|
|
294
|
-
this.logger.info(`Task run ${action.
|
|
294
|
+
this.logger.info(`Task run ${action.taskRunExternalId} succeeded`);
|
|
295
295
|
try {
|
|
296
296
|
// Send the action event to the dispatcher
|
|
297
297
|
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_COMPLETED, result);
|
|
@@ -345,8 +345,8 @@ class V0Worker {
|
|
|
345
345
|
workerId: this.name,
|
|
346
346
|
jobId: action.jobId,
|
|
347
347
|
jobRunId: action.jobRunId,
|
|
348
|
-
|
|
349
|
-
|
|
348
|
+
taskId: action.taskId,
|
|
349
|
+
taskRunExternalId: action.taskRunExternalId,
|
|
350
350
|
actionId: action.actionId,
|
|
351
351
|
eventTimestamp: new Date(),
|
|
352
352
|
eventType,
|
|
@@ -371,9 +371,9 @@ class V0Worker {
|
|
|
371
371
|
}
|
|
372
372
|
handleCancelStepRun(action) {
|
|
373
373
|
return __awaiter(this, void 0, void 0, function* () {
|
|
374
|
-
const {
|
|
374
|
+
const { taskRunExternalId } = action;
|
|
375
375
|
try {
|
|
376
|
-
this.logger.info(`Cancelling task run ${action.
|
|
376
|
+
this.logger.info(`Cancelling task run ${action.taskRunExternalId}`);
|
|
377
377
|
const future = this.futures[(0, action_listener_1.createActionKey)(action)];
|
|
378
378
|
const context = this.contexts[(0, action_listener_1.createActionKey)(action)];
|
|
379
379
|
if (context && context.controller) {
|
|
@@ -381,7 +381,7 @@ class V0Worker {
|
|
|
381
381
|
}
|
|
382
382
|
if (future) {
|
|
383
383
|
future.promise.catch(() => {
|
|
384
|
-
this.logger.info(`Cancelled task run ${action.
|
|
384
|
+
this.logger.info(`Cancelled task run ${action.taskRunExternalId}`);
|
|
385
385
|
});
|
|
386
386
|
future.cancel('Cancelled by worker');
|
|
387
387
|
yield future.promise;
|
|
@@ -389,7 +389,7 @@ class V0Worker {
|
|
|
389
389
|
}
|
|
390
390
|
catch (e) {
|
|
391
391
|
// Expected: the promise rejects when cancelled
|
|
392
|
-
this.logger.debug(`Task run ${
|
|
392
|
+
this.logger.debug(`Task run ${taskRunExternalId} cancellation completed`);
|
|
393
393
|
}
|
|
394
394
|
finally {
|
|
395
395
|
delete this.futures[(0, action_listener_1.createActionKey)(action)];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const sdk_1 = __importDefault(require("../sdk"));
|
|
16
|
+
const data_contracts_1 = require("../clients/rest/generated/data-contracts");
|
|
17
|
+
const hatchet = sdk_1.default.init();
|
|
18
|
+
function main() {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
var _a, _b, _c, _d;
|
|
21
|
+
const webhookName = `example-webhook-${Date.now()}`;
|
|
22
|
+
const namespace = (_b = (_a = hatchet.config) === null || _a === void 0 ? void 0 : _a.namespace) !== null && _b !== void 0 ? _b : 'default';
|
|
23
|
+
const webhook = yield hatchet.webhooks.create({
|
|
24
|
+
sourceName: data_contracts_1.V1WebhookSourceName.GENERIC,
|
|
25
|
+
name: webhookName,
|
|
26
|
+
eventKeyExpression: `'${namespace}/webhook:' + input.type`,
|
|
27
|
+
scopeExpression: 'input.customer_id',
|
|
28
|
+
staticPayload: { customer_id: 'cust-123', environment: 'production' },
|
|
29
|
+
auth: { username: 'test_user', password: 'test_password' },
|
|
30
|
+
});
|
|
31
|
+
console.log('Created webhook:', webhook.name, webhook.scopeExpression, webhook.staticPayload);
|
|
32
|
+
const one = yield hatchet.webhooks.get(webhook.name);
|
|
33
|
+
console.log('Get webhook:', one.name);
|
|
34
|
+
yield hatchet.webhooks.update(webhook.name, {
|
|
35
|
+
scopeExpression: 'input.environment',
|
|
36
|
+
});
|
|
37
|
+
const updated = yield hatchet.webhooks.get(webhook.name);
|
|
38
|
+
console.log('Updated scope expression:', updated.scopeExpression);
|
|
39
|
+
const list = yield hatchet.webhooks.list({ limit: 10, offset: 0 });
|
|
40
|
+
console.log('List webhooks:', (_d = (_c = list.rows) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0);
|
|
41
|
+
yield hatchet.webhooks.delete(webhook.name);
|
|
42
|
+
console.log('Deleted example webhook');
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
main();
|
package/package.json
CHANGED
|
@@ -82,8 +82,8 @@ export interface WorkerRegisterRequest {
|
|
|
82
82
|
actions: string[];
|
|
83
83
|
/** (optional) the services for this worker */
|
|
84
84
|
services: string[];
|
|
85
|
-
/** (optional) the
|
|
86
|
-
|
|
85
|
+
/** (optional) the number of slots this worker can handle */
|
|
86
|
+
slots?: number | undefined;
|
|
87
87
|
/** (optional) worker labels (i.e. state or other metadata) */
|
|
88
88
|
labels: {
|
|
89
89
|
[key: string]: WorkerLabels;
|
|
@@ -136,18 +136,18 @@ export interface AssignedAction {
|
|
|
136
136
|
jobName: string;
|
|
137
137
|
/** the job run id */
|
|
138
138
|
jobRunId: string;
|
|
139
|
-
/** the
|
|
140
|
-
|
|
141
|
-
/** the
|
|
142
|
-
|
|
139
|
+
/** the task id */
|
|
140
|
+
taskId: string;
|
|
141
|
+
/** the task external run id */
|
|
142
|
+
taskRunExternalId: string;
|
|
143
143
|
/** the action id */
|
|
144
144
|
actionId: string;
|
|
145
145
|
/** the action type */
|
|
146
146
|
actionType: ActionType;
|
|
147
147
|
/** the action payload */
|
|
148
148
|
actionPayload: string;
|
|
149
|
-
/** the
|
|
150
|
-
|
|
149
|
+
/** the task name */
|
|
150
|
+
taskName: string;
|
|
151
151
|
/** the count number of the retry attempt */
|
|
152
152
|
retryCount: number;
|
|
153
153
|
/** (optional) additional metadata set on the workflow */
|
|
@@ -188,7 +188,7 @@ export interface GroupKeyActionEvent {
|
|
|
188
188
|
/** the action id */
|
|
189
189
|
actionId: string;
|
|
190
190
|
eventTimestamp: Date | undefined;
|
|
191
|
-
/** the
|
|
191
|
+
/** the task event type */
|
|
192
192
|
eventType: GroupKeyActionEventType;
|
|
193
193
|
/** the event payload */
|
|
194
194
|
eventPayload: string;
|
|
@@ -200,14 +200,14 @@ export interface StepActionEvent {
|
|
|
200
200
|
jobId: string;
|
|
201
201
|
/** the job run id */
|
|
202
202
|
jobRunId: string;
|
|
203
|
-
/** the id of the
|
|
204
|
-
|
|
205
|
-
/** the
|
|
206
|
-
|
|
203
|
+
/** the id of the task */
|
|
204
|
+
taskId: string;
|
|
205
|
+
/** the task external run id */
|
|
206
|
+
taskRunExternalId: string;
|
|
207
207
|
/** the action id */
|
|
208
208
|
actionId: string;
|
|
209
209
|
eventTimestamp: Date | undefined;
|
|
210
|
-
/** the
|
|
210
|
+
/** the task event type */
|
|
211
211
|
eventType: StepActionEventType;
|
|
212
212
|
/** the event payload */
|
|
213
213
|
eventPayload: string;
|
|
@@ -248,9 +248,9 @@ export interface WorkflowEvent {
|
|
|
248
248
|
* will hang up the connection but clients might want to case
|
|
249
249
|
*/
|
|
250
250
|
hangup: boolean;
|
|
251
|
-
/** (optional) the max number of retries this
|
|
252
|
-
|
|
253
|
-
/** (optional) the retry count of this
|
|
251
|
+
/** (optional) the max number of retries this task can handle */
|
|
252
|
+
taskRetries?: number | undefined;
|
|
253
|
+
/** (optional) the retry count of this task */
|
|
254
254
|
retryCount?: number | undefined;
|
|
255
255
|
eventIndex?: number | undefined;
|
|
256
256
|
}
|
|
@@ -262,15 +262,15 @@ export interface WorkflowRunEvent {
|
|
|
262
262
|
results: StepRunResult[];
|
|
263
263
|
}
|
|
264
264
|
export interface StepRunResult {
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
taskRunExternalId: string;
|
|
266
|
+
taskName: string;
|
|
267
267
|
jobRunId: string;
|
|
268
268
|
error?: string | undefined;
|
|
269
269
|
output?: string | undefined;
|
|
270
270
|
}
|
|
271
271
|
export interface OverridesData {
|
|
272
|
-
/** the
|
|
273
|
-
|
|
272
|
+
/** the task run id */
|
|
273
|
+
taskRunExternalId: string;
|
|
274
274
|
/** the path of the data to set */
|
|
275
275
|
path: string;
|
|
276
276
|
/** the value to set */
|
|
@@ -289,16 +289,16 @@ export interface HeartbeatRequest {
|
|
|
289
289
|
export interface HeartbeatResponse {
|
|
290
290
|
}
|
|
291
291
|
export interface RefreshTimeoutRequest {
|
|
292
|
-
/** the id of the
|
|
293
|
-
|
|
292
|
+
/** the id of the task run to release */
|
|
293
|
+
taskRunExternalId: string;
|
|
294
294
|
incrementTimeoutBy: string;
|
|
295
295
|
}
|
|
296
296
|
export interface RefreshTimeoutResponse {
|
|
297
297
|
timeoutAt: Date | undefined;
|
|
298
298
|
}
|
|
299
299
|
export interface ReleaseSlotRequest {
|
|
300
|
-
/** the id of the
|
|
301
|
-
|
|
300
|
+
/** the id of the task run to release */
|
|
301
|
+
taskRunExternalId: string;
|
|
302
302
|
}
|
|
303
303
|
export interface ReleaseSlotResponse {
|
|
304
304
|
}
|