@hatchet-dev/typescript-sdk 1.10.7 → 1.11.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/rest/generated/data-contracts.d.ts +12 -0
- package/clients/worker/worker.js +16 -8
- package/package.json +1 -1
- package/v1/client/features/metrics.d.ts +16 -5
- package/v1/client/features/metrics.js +13 -14
- package/v1/client/worker/worker-internal.js +16 -8
- package/v1/declaration.d.ts +2 -2
- package/v1/declaration.js +23 -9
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -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 */
|
|
@@ -863,6 +871,10 @@ export type V1CreateWebhookRequest = V1CreateWebhookRequestBasicAuth | V1CreateW
|
|
|
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
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(`
|
|
190
|
+
this.logger.info(`Task run ${action.stepRunId} 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(`
|
|
215
|
+
this.logger.error(`Task run ${action.stepRunId} failed: ${error.message}`);
|
|
216
216
|
if (error.stack) {
|
|
217
217
|
this.logger.error(error.stack);
|
|
218
218
|
}
|
|
@@ -255,7 +255,14 @@ class V0Worker {
|
|
|
255
255
|
yield future.promise;
|
|
256
256
|
}
|
|
257
257
|
catch (e) {
|
|
258
|
-
|
|
258
|
+
const message = (e === null || e === void 0 ? void 0 : e.message) || String(e);
|
|
259
|
+
if (message.includes('Cancelled')) {
|
|
260
|
+
this.logger.debug(`Task run ${action.stepRunId} was cancelled`);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
this.logger.error(`Could not wait for task run ${action.stepRunId} to finish. ` +
|
|
264
|
+
`See https://docs.hatchet.run/home/cancellation for best practices on handling cancellation: `, e);
|
|
265
|
+
}
|
|
259
266
|
}
|
|
260
267
|
}
|
|
261
268
|
catch (e) {
|
|
@@ -284,7 +291,7 @@ class V0Worker {
|
|
|
284
291
|
return step(context);
|
|
285
292
|
});
|
|
286
293
|
const success = (result) => {
|
|
287
|
-
this.logger.info(`
|
|
294
|
+
this.logger.info(`Task run ${action.stepRunId} succeeded`);
|
|
288
295
|
try {
|
|
289
296
|
// Send the action event to the dispatcher
|
|
290
297
|
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_COMPLETED, result);
|
|
@@ -302,7 +309,7 @@ class V0Worker {
|
|
|
302
309
|
}
|
|
303
310
|
};
|
|
304
311
|
const failure = (error) => {
|
|
305
|
-
this.logger.error(`
|
|
312
|
+
this.logger.error(`Task run ${key} failed: ${error.message}`);
|
|
306
313
|
try {
|
|
307
314
|
// Send the action event to the dispatcher
|
|
308
315
|
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_FAILED, error);
|
|
@@ -366,7 +373,7 @@ class V0Worker {
|
|
|
366
373
|
return __awaiter(this, void 0, void 0, function* () {
|
|
367
374
|
const { stepRunId } = action;
|
|
368
375
|
try {
|
|
369
|
-
this.logger.info(`Cancelling
|
|
376
|
+
this.logger.info(`Cancelling task run ${action.stepRunId}`);
|
|
370
377
|
const future = this.futures[(0, action_listener_1.createActionKey)(action)];
|
|
371
378
|
const context = this.contexts[(0, action_listener_1.createActionKey)(action)];
|
|
372
379
|
if (context && context.controller) {
|
|
@@ -374,14 +381,15 @@ class V0Worker {
|
|
|
374
381
|
}
|
|
375
382
|
if (future) {
|
|
376
383
|
future.promise.catch(() => {
|
|
377
|
-
this.logger.info(`Cancelled
|
|
384
|
+
this.logger.info(`Cancelled task run ${action.stepRunId}`);
|
|
378
385
|
});
|
|
379
386
|
future.cancel('Cancelled by worker');
|
|
380
387
|
yield future.promise;
|
|
381
388
|
}
|
|
382
389
|
}
|
|
383
390
|
catch (e) {
|
|
384
|
-
|
|
391
|
+
// Expected: the promise rejects when cancelled
|
|
392
|
+
this.logger.debug(`Task run ${stepRunId} cancellation completed`);
|
|
385
393
|
}
|
|
386
394
|
finally {
|
|
387
395
|
delete this.futures[(0, action_listener_1.createActionKey)(action)];
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { BaseWorkflowDeclaration } from '../..';
|
|
2
|
-
import { Workflow } from '../../../workflow';
|
|
3
1
|
import { HatchetClient } from '../client';
|
|
2
|
+
export type TaskStatusMetrics = {
|
|
3
|
+
cancelled: number;
|
|
4
|
+
completed: number;
|
|
5
|
+
failed: number;
|
|
6
|
+
queued: number;
|
|
7
|
+
running: number;
|
|
8
|
+
};
|
|
4
9
|
/**
|
|
5
10
|
* MetricsClient is used to get metrics for workflows
|
|
6
11
|
*/
|
|
@@ -8,7 +13,13 @@ export declare class MetricsClient {
|
|
|
8
13
|
tenantId: string;
|
|
9
14
|
api: HatchetClient['api'];
|
|
10
15
|
constructor(client: HatchetClient);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Get task/run status metrics for a tenant.
|
|
18
|
+
*
|
|
19
|
+
* This backs the dashboard "runs list" status count badges.
|
|
20
|
+
*
|
|
21
|
+
* Endpoint: GET /api/v1/stable/tenants/{tenant}/task-metrics
|
|
22
|
+
*/
|
|
23
|
+
getTaskStatusMetrics(query: Parameters<typeof this.api.v1TaskListStatusMetrics>[1], requestParams?: Parameters<typeof this.api.v1TaskListStatusMetrics>[2]): Promise<TaskStatusMetrics>;
|
|
24
|
+
getQueueMetrics(opts?: Parameters<typeof this.api.tenantGetStepRunQueueMetrics>[1]): Promise<import("../../../clients/rest/generated/data-contracts").TenantStepRunQueueMetrics>;
|
|
14
25
|
}
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MetricsClient = void 0;
|
|
13
|
-
const v1_1 = require("../..");
|
|
14
13
|
/**
|
|
15
14
|
* MetricsClient is used to get metrics for workflows
|
|
16
15
|
*/
|
|
@@ -19,24 +18,24 @@ class MetricsClient {
|
|
|
19
18
|
this.tenantId = client.tenantId;
|
|
20
19
|
this.api = client.api;
|
|
21
20
|
}
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Get task/run status metrics for a tenant.
|
|
23
|
+
*
|
|
24
|
+
* This backs the dashboard "runs list" status count badges.
|
|
25
|
+
*
|
|
26
|
+
* Endpoint: GET /api/v1/stable/tenants/{tenant}/task-metrics
|
|
27
|
+
*/
|
|
28
|
+
getTaskStatusMetrics(query, requestParams) {
|
|
23
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
const { data } = yield this.api.v1TaskListStatusMetrics(this.tenantId, query, requestParams);
|
|
31
|
+
return data.reduce((acc, curr) => {
|
|
32
|
+
acc[curr.status.toLowerCase()] = curr.count;
|
|
33
|
+
return acc;
|
|
34
|
+
}, {});
|
|
27
35
|
});
|
|
28
36
|
}
|
|
29
37
|
getQueueMetrics(opts) {
|
|
30
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
// TODO IMPORTANT workflow id is the uuid for the workflow... not its name
|
|
32
|
-
// const stringWorkflows = opts?.workflows?
|
|
33
|
-
const { data } = yield this.api.tenantGetQueueMetrics(this.tenantId, Object.assign({}, opts));
|
|
34
|
-
return data;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
getTaskMetrics(opts) {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
// TODO what is this...
|
|
40
39
|
const { data } = yield this.api.tenantGetStepRunQueueMetrics(this.tenantId, opts);
|
|
41
40
|
return data;
|
|
42
41
|
});
|
|
@@ -423,7 +423,7 @@ class V1Worker {
|
|
|
423
423
|
if (context.cancelled) {
|
|
424
424
|
return;
|
|
425
425
|
}
|
|
426
|
-
this.logger.info(`
|
|
426
|
+
this.logger.info(`Task run ${action.stepRunId} succeeded`);
|
|
427
427
|
// Send the action event to the dispatcher
|
|
428
428
|
const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, false, result || null, action.retryCount);
|
|
429
429
|
yield this.client._v0.dispatcher.sendStepActionEvent(event);
|
|
@@ -452,7 +452,7 @@ class V1Worker {
|
|
|
452
452
|
if (context.cancelled) {
|
|
453
453
|
return;
|
|
454
454
|
}
|
|
455
|
-
this.logger.error(`
|
|
455
|
+
this.logger.error(`Task run ${action.stepRunId} failed: ${error.message}`);
|
|
456
456
|
if (error.stack) {
|
|
457
457
|
this.logger.error(error.stack);
|
|
458
458
|
}
|
|
@@ -493,7 +493,14 @@ class V1Worker {
|
|
|
493
493
|
yield future.promise;
|
|
494
494
|
}
|
|
495
495
|
catch (e) {
|
|
496
|
-
|
|
496
|
+
const message = (e === null || e === void 0 ? void 0 : e.message) || String(e);
|
|
497
|
+
if (message.includes('Cancelled')) {
|
|
498
|
+
this.logger.debug(`Task run ${action.stepRunId} was cancelled`);
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
this.logger.error(`Could not wait for task run ${action.stepRunId} to finish. ` +
|
|
502
|
+
`See https://docs.hatchet.run/home/cancellation for best practices on handling cancellation: `, e);
|
|
503
|
+
}
|
|
497
504
|
}
|
|
498
505
|
}
|
|
499
506
|
catch (e) {
|
|
@@ -523,7 +530,7 @@ class V1Worker {
|
|
|
523
530
|
return step(context);
|
|
524
531
|
});
|
|
525
532
|
const success = (result) => {
|
|
526
|
-
this.logger.info(`
|
|
533
|
+
this.logger.info(`Task run ${action.stepRunId} succeeded`);
|
|
527
534
|
try {
|
|
528
535
|
// Send the action event to the dispatcher
|
|
529
536
|
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_COMPLETED, result);
|
|
@@ -541,7 +548,7 @@ class V1Worker {
|
|
|
541
548
|
}
|
|
542
549
|
};
|
|
543
550
|
const failure = (error) => {
|
|
544
|
-
this.logger.error(`
|
|
551
|
+
this.logger.error(`Task run ${key} failed: ${error.message}`);
|
|
545
552
|
try {
|
|
546
553
|
// Send the action event to the dispatcher
|
|
547
554
|
const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_FAILED, error);
|
|
@@ -605,7 +612,7 @@ class V1Worker {
|
|
|
605
612
|
return __awaiter(this, void 0, void 0, function* () {
|
|
606
613
|
const { stepRunId } = action;
|
|
607
614
|
try {
|
|
608
|
-
this.logger.info(`Cancelling
|
|
615
|
+
this.logger.info(`Cancelling task run ${action.stepRunId}`);
|
|
609
616
|
const future = this.futures[stepRunId];
|
|
610
617
|
const context = this.contexts[stepRunId];
|
|
611
618
|
if (context && context.abortController) {
|
|
@@ -613,14 +620,15 @@ class V1Worker {
|
|
|
613
620
|
}
|
|
614
621
|
if (future) {
|
|
615
622
|
future.promise.catch(() => {
|
|
616
|
-
this.logger.info(`Cancelled
|
|
623
|
+
this.logger.info(`Cancelled task run ${action.stepRunId}`);
|
|
617
624
|
});
|
|
618
625
|
future.cancel('Cancelled by worker');
|
|
619
626
|
yield future.promise;
|
|
620
627
|
}
|
|
621
628
|
}
|
|
622
629
|
catch (e) {
|
|
623
|
-
|
|
630
|
+
// Expected: the promise rejects when cancelled
|
|
631
|
+
this.logger.debug(`Task run ${stepRunId} cancellation completed`);
|
|
624
632
|
}
|
|
625
633
|
finally {
|
|
626
634
|
delete this.futures[stepRunId];
|
package/v1/declaration.d.ts
CHANGED
|
@@ -266,14 +266,14 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
|
|
|
266
266
|
* @returns A promise that resolves with the workflow metrics.
|
|
267
267
|
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
268
268
|
*/
|
|
269
|
-
metrics(opts?: Parameters<MetricsClient['
|
|
269
|
+
metrics(opts?: Omit<Parameters<MetricsClient['getTaskStatusMetrics']>[0], 'workflows'>): Promise<import("./client/features/metrics").TaskStatusMetrics>;
|
|
270
270
|
/**
|
|
271
271
|
* Get queue metrics for the workflow.
|
|
272
272
|
* @param opts Optional configuration for the metrics request.
|
|
273
273
|
* @returns A promise that resolves with the workflow metrics.
|
|
274
274
|
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
275
275
|
*/
|
|
276
|
-
|
|
276
|
+
taskStatusMetrics(opts?: Omit<Parameters<MetricsClient['getTaskStatusMetrics']>[0], 'workflows'>): Promise<import("./client/features/metrics").TaskStatusMetrics>;
|
|
277
277
|
/**
|
|
278
278
|
* Get the current state of the workflow.
|
|
279
279
|
* @returns A promise that resolves with the workflow state.
|
package/v1/declaration.js
CHANGED
|
@@ -166,10 +166,17 @@ class BaseWorkflowDeclaration {
|
|
|
166
166
|
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
167
167
|
*/
|
|
168
168
|
metrics(opts) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
if (!this.client) {
|
|
171
|
+
throw UNBOUND_ERR;
|
|
172
|
+
}
|
|
173
|
+
const workflow = yield this.client.workflows.get(this.definition.name);
|
|
174
|
+
return this.client.metrics.getTaskStatusMetrics({
|
|
175
|
+
since: (opts === null || opts === void 0 ? void 0 : opts.since) || new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
|
|
176
|
+
until: (opts === null || opts === void 0 ? void 0 : opts.until) || new Date().toISOString(),
|
|
177
|
+
workflow_ids: [workflow.metadata.id],
|
|
178
|
+
});
|
|
179
|
+
});
|
|
173
180
|
}
|
|
174
181
|
/**
|
|
175
182
|
* Get queue metrics for the workflow.
|
|
@@ -177,11 +184,18 @@ class BaseWorkflowDeclaration {
|
|
|
177
184
|
* @returns A promise that resolves with the workflow metrics.
|
|
178
185
|
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
179
186
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
187
|
+
taskStatusMetrics(opts) {
|
|
188
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
if (!this.client) {
|
|
190
|
+
throw UNBOUND_ERR;
|
|
191
|
+
}
|
|
192
|
+
const workflow = yield this.client.workflows.get(this.definition.name);
|
|
193
|
+
return this.client.metrics.getTaskStatusMetrics({
|
|
194
|
+
since: (opts === null || opts === void 0 ? void 0 : opts.since) || new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
|
|
195
|
+
until: (opts === null || opts === void 0 ? void 0 : opts.until) || new Date().toISOString(),
|
|
196
|
+
workflow_ids: [workflow.metadata.id],
|
|
197
|
+
});
|
|
198
|
+
});
|
|
185
199
|
}
|
|
186
200
|
/**
|
|
187
201
|
* Get the current state of the workflow.
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.11.0";
|
package/version.js
CHANGED