@hatchet-dev/typescript-sdk 1.15.2 → 1.16.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.js +8 -9
- package/clients/dispatcher/action-listener.js +42 -6
- package/clients/dispatcher/dispatcher-client.js +5 -8
- package/clients/dispatcher/heartbeat/heartbeat-worker.js +7 -4
- package/clients/event/event-client.d.ts +2 -2
- package/clients/event/event-client.js +5 -11
- package/clients/hatchet-client/hatchet-logger.js +8 -17
- package/clients/listeners/durable-listener/pooled-durable-listener-client.js +10 -8
- package/clients/listeners/run-listener/child-listener-client.d.ts +1 -1
- package/clients/listeners/run-listener/child-listener-client.js +34 -30
- package/clients/listeners/run-listener/pooled-child-listener-client.js +8 -5
- package/clients/rest/generated/Api.d.ts +21 -1
- package/clients/rest/generated/Api.js +20 -0
- package/clients/rest/generated/data-contracts.d.ts +46 -1
- package/clients/rest/generated/data-contracts.js +4 -0
- package/legacy/examples/affinity-workers.js +0 -1
- package/legacy/examples/byo-logger.js +0 -2
- package/legacy/examples/concurrency/cancel-in-progress/concurrency-worker.js +4 -2
- package/legacy/examples/concurrency/group-round-robin/concurrency-event.js +0 -1
- package/legacy/examples/concurrency/group-round-robin/concurrency-worker-expression.js +4 -2
- package/legacy/examples/concurrency/group-round-robin/concurrency-worker-key-fn.js +4 -2
- package/legacy/examples/example-event.js +0 -3
- package/legacy/examples/logger.js +0 -1
- package/legacy/examples/sticky-worker-with-check.js +0 -1
- package/legacy/examples/sticky-worker.js +0 -1
- package/legacy/legacy-client.js +1 -1
- package/legacy/legacy-transformer.js +2 -4
- package/legacy/step.d.ts +14 -14
- package/legacy/step.js +5 -15
- package/legacy/workflow.d.ts +56 -56
- package/package.json +20 -29
- package/util/abort-error.d.ts +5 -1
- package/util/abort-error.js +15 -5
- package/util/config-loader/config-loader.js +4 -3
- package/util/config-loader/token.js +9 -2
- package/util/errors/hatchet-error.d.ts +9 -1
- package/util/errors/hatchet-error.js +23 -2
- package/util/grpc-error.d.ts +9 -0
- package/util/grpc-error.js +25 -0
- package/util/hatchet-promise/hatchet-promise.d.ts +5 -1
- package/util/hatchet-promise/hatchet-promise.js +6 -1
- package/util/logger/logger.js +0 -1
- package/util/parse.d.ts +1 -1
- package/util/parse.js +4 -2
- package/util/retrier.js +2 -3
- package/util/workflow-run-ref.js +5 -3
- package/v1/client/admin.js +2 -6
- package/v1/client/client.d.ts +7 -11
- package/v1/client/client.interface.d.ts +5 -8
- package/v1/client/client.js +33 -39
- package/v1/client/features/cel.js +1 -1
- package/v1/client/features/crons.js +2 -2
- package/v1/client/features/index.d.ts +5 -0
- package/v1/client/features/index.js +5 -0
- package/v1/client/features/logs.d.ts +37 -0
- package/v1/client/features/logs.js +46 -0
- package/v1/client/features/runs.js +0 -1
- package/v1/client/features/schedules.js +4 -4
- package/v1/client/features/webhooks.js +4 -2
- package/v1/client/features/workflows.js +1 -1
- package/v1/client/worker/context.js +10 -23
- package/v1/client/worker/deprecated/deprecation.js +8 -4
- package/v1/client/worker/deprecated/legacy-worker.js +2 -2
- package/v1/client/worker/health-server.js +3 -3
- package/v1/client/worker/slot-utils.js +0 -3
- package/v1/client/worker/worker-internal.js +39 -10
- package/v1/client/worker/worker.js +2 -1
- package/v1/conditions/base.js +0 -1
- package/v1/conditions/index.js +2 -4
- package/v1/declaration.d.ts +1 -1
- package/v1/declaration.js +12 -7
- package/v1/examples/__e2e__/harness.js +4 -3
- package/v1/examples/affinity/affinity-workers.js +0 -1
- package/v1/examples/bulk_operations/workflow.js +0 -1
- package/v1/examples/cancellation/run.js +0 -1
- package/v1/examples/cancellations/run.js +0 -1
- package/v1/examples/child_workflows/run.js +0 -2
- package/v1/examples/child_workflows/workflow.js +0 -1
- package/v1/examples/concurrency-rr/load.js +0 -1
- package/v1/examples/concurrency-rr/run.js +0 -3
- package/v1/examples/concurrency_limit_rr/load.js +0 -1
- package/v1/examples/concurrency_limit_rr/run.js +0 -3
- package/v1/examples/conditions/event.js +0 -1
- package/v1/examples/conditions/run.js +0 -1
- package/v1/examples/dag/run.js +0 -1
- package/v1/examples/dag_match_condition/event.js +0 -1
- package/v1/examples/dag_match_condition/run.js +0 -1
- package/v1/examples/deep/run.js +0 -2
- package/v1/examples/durable/workflow.js +2 -3
- package/v1/examples/durable-event/event.js +0 -1
- package/v1/examples/durable-event/run.js +0 -2
- package/v1/examples/durable-sleep/event.js +0 -1
- package/v1/examples/durable-sleep/run.js +0 -2
- package/v1/examples/durable_event/event.js +0 -1
- package/v1/examples/durable_event/run.js +0 -2
- package/v1/examples/durable_sleep/event.js +0 -1
- package/v1/examples/durable_sleep/run.js +0 -2
- package/v1/examples/events/event.js +0 -1
- package/v1/examples/high-memory/run.js +0 -1
- package/v1/examples/inferred-typing/run.js +0 -1
- package/v1/examples/landing_page/durable-excution.js +0 -1
- package/v1/examples/landing_page/queues.js +0 -1
- package/v1/examples/legacy/run.js +0 -1
- package/v1/examples/logger/byo-logger.js +0 -2
- package/v1/examples/logger/logger.js +0 -1
- package/v1/examples/logging/byo-logger.js +0 -2
- package/v1/examples/logging/logger.js +0 -1
- package/v1/examples/middleware/recipes.js +3 -1
- package/v1/examples/migration-guides/mergent.js +2 -1
- package/v1/examples/multiple_wf_concurrency/run.js +0 -3
- package/v1/examples/non_retryable/run.js +0 -1
- package/v1/examples/on_event/event.js +0 -1
- package/v1/examples/on_failure/run.js +0 -1
- package/v1/examples/on_failure/workflow.js +0 -1
- package/v1/examples/on_success/run.js +0 -1
- package/v1/examples/on_success/workflow.js +0 -1
- package/v1/examples/priority/run.js +0 -1
- package/v1/examples/priority/workflow.js +0 -1
- package/v1/examples/retries/run.js +0 -1
- package/v1/examples/retries/workflow.js +0 -1
- package/v1/examples/simple/bulk.js +0 -1
- package/v1/examples/simple/cron.js +0 -2
- package/v1/examples/simple/delay.js +0 -1
- package/v1/examples/simple/enqueue.js +0 -2
- package/v1/examples/simple/run.js +0 -1
- package/v1/examples/simple/schedule.js +0 -1
- package/v1/examples/simple/workflow-with-child.js +10 -4
- package/v1/examples/sticky/run.js +0 -1
- package/v1/examples/sticky/workflow.js +0 -1
- package/v1/examples/streaming/nextjs-proxy.js +0 -1
- package/v1/examples/streaming/run.js +0 -1
- package/v1/examples/timeout/run.js +0 -1
- package/v1/examples/timeouts/run.js +0 -1
- package/v1/slot-types.js +0 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -25,7 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.AdminClient = void 0;
|
|
27
27
|
const workflows_1 = require("../../protoc/workflows");
|
|
28
|
-
const hatchet_error_1 =
|
|
28
|
+
const hatchet_error_1 = require("../../util/errors/hatchet-error");
|
|
29
29
|
const retrier_1 = require("../../util/retrier");
|
|
30
30
|
const workflow_run_ref_1 = __importDefault(require("../../util/workflow-run-ref"));
|
|
31
31
|
const workflows_2 = require("../../protoc/v1/workflows");
|
|
@@ -72,7 +72,7 @@ class AdminClient {
|
|
|
72
72
|
return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.putWorkflow({ opts: workflow }); }), this.logger);
|
|
73
73
|
}
|
|
74
74
|
catch (e) {
|
|
75
|
-
throw
|
|
75
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
}
|
|
@@ -87,7 +87,7 @@ class AdminClient {
|
|
|
87
87
|
return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.v1Client.putWorkflow(workflow); }), this.logger);
|
|
88
88
|
}
|
|
89
89
|
catch (e) {
|
|
90
|
-
throw
|
|
90
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
93
|
}
|
|
@@ -114,7 +114,7 @@ class AdminClient {
|
|
|
114
114
|
}), this.logger);
|
|
115
115
|
}
|
|
116
116
|
catch (e) {
|
|
117
|
-
throw
|
|
117
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
120
|
}
|
|
@@ -153,7 +153,7 @@ class AdminClient {
|
|
|
153
153
|
return new workflow_run_ref_1.default(resp, this.listenerClient, this.workflows, options === null || options === void 0 ? void 0 : options.parentId);
|
|
154
154
|
}
|
|
155
155
|
catch (e) {
|
|
156
|
-
throw
|
|
156
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
@@ -186,7 +186,7 @@ class AdminClient {
|
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
188
|
catch (e) {
|
|
189
|
-
throw
|
|
189
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
@@ -301,9 +301,8 @@ class AdminClient {
|
|
|
301
301
|
* @deprecated use hatchet.schedules.create instead
|
|
302
302
|
*/
|
|
303
303
|
scheduleWorkflow(name, options) {
|
|
304
|
-
let computedName = name;
|
|
305
304
|
try {
|
|
306
|
-
computedName = (0, apply_namespace_1.applyNamespace)(name, this.config.namespace);
|
|
305
|
+
const computedName = (0, apply_namespace_1.applyNamespace)(name, this.config.namespace);
|
|
307
306
|
let input;
|
|
308
307
|
if (options === null || options === void 0 ? void 0 : options.input) {
|
|
309
308
|
input = JSON.stringify(options.input);
|
|
@@ -315,7 +314,7 @@ class AdminClient {
|
|
|
315
314
|
});
|
|
316
315
|
}
|
|
317
316
|
catch (e) {
|
|
318
|
-
throw
|
|
317
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
319
318
|
}
|
|
320
319
|
}
|
|
321
320
|
/**
|
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -36,13 +69,13 @@ exports.ActionListener = void 0;
|
|
|
36
69
|
exports.createActionKey = createActionKey;
|
|
37
70
|
const dispatcher_1 = require("../../protoc/dispatcher");
|
|
38
71
|
const nice_grpc_1 = require("nice-grpc");
|
|
72
|
+
const grpc_error_1 = require("../../util/grpc-error");
|
|
39
73
|
const abort_controller_x_1 = require("abort-controller-x");
|
|
40
74
|
const sleep_1 = __importDefault(require("../../util/sleep"));
|
|
41
|
-
const hatchet_error_1 =
|
|
75
|
+
const hatchet_error_1 = __importStar(require("../../util/errors/hatchet-error"));
|
|
42
76
|
const heartbeat_controller_1 = require("./heartbeat/heartbeat-controller");
|
|
43
77
|
const DEFAULT_ACTION_LISTENER_RETRY_INTERVAL = 5000; // milliseconds
|
|
44
78
|
const DEFAULT_ACTION_LISTENER_RETRY_COUNT = 20;
|
|
45
|
-
// eslint-disable-next-line no-shadow
|
|
46
79
|
var ListenStrategy;
|
|
47
80
|
(function (ListenStrategy) {
|
|
48
81
|
ListenStrategy[ListenStrategy["LISTEN_STRATEGY_V1"] = 1] = "LISTEN_STRATEGY_V1";
|
|
@@ -108,11 +141,11 @@ class ActionListener {
|
|
|
108
141
|
throw e;
|
|
109
142
|
}
|
|
110
143
|
if ((yield __await(client.getListenStrategy())) === ListenStrategy.LISTEN_STRATEGY_V2 &&
|
|
111
|
-
e
|
|
144
|
+
(0, grpc_error_1.getGrpcErrorCode)(e) === nice_grpc_1.Status.UNIMPLEMENTED) {
|
|
112
145
|
client.setListenStrategy(ListenStrategy.LISTEN_STRATEGY_V1);
|
|
113
146
|
}
|
|
114
147
|
client.incrementRetries();
|
|
115
|
-
client.logger.error(`Listener encountered an error: ${e
|
|
148
|
+
client.logger.error(`Listener encountered an error: ${(0, hatchet_error_1.getErrorMessage)(e)}`);
|
|
116
149
|
if (client.retries > 1) {
|
|
117
150
|
client.logger.info(`Retrying in ${client.retryInterval}ms...`);
|
|
118
151
|
yield __await((0, sleep_1.default)(client.retryInterval));
|
|
@@ -186,7 +219,7 @@ class ActionListener {
|
|
|
186
219
|
catch (e) {
|
|
187
220
|
this.retries += 1;
|
|
188
221
|
this.logger.error(`Attempt ${this.retries}: Failed to connect, retrying...`);
|
|
189
|
-
if (e
|
|
222
|
+
if ((0, grpc_error_1.getGrpcErrorCode)(e) === nice_grpc_1.Status.UNAVAILABLE) {
|
|
190
223
|
// Connection lost, reset heartbeat interval and retry connection
|
|
191
224
|
this.heartbeat.stop();
|
|
192
225
|
return this.getListenClient();
|
|
@@ -209,7 +242,10 @@ class ActionListener {
|
|
|
209
242
|
});
|
|
210
243
|
}
|
|
211
244
|
catch (e) {
|
|
212
|
-
throw
|
|
245
|
+
throw (0, hatchet_error_1.toHatchetError)(e, {
|
|
246
|
+
defaultMessage: 'Failed to unsubscribe',
|
|
247
|
+
prefix: 'Failed to unsubscribe: ',
|
|
248
|
+
});
|
|
213
249
|
}
|
|
214
250
|
});
|
|
215
251
|
}
|
|
@@ -19,14 +19,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
}
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
23
|
exports.DispatcherClient = void 0;
|
|
27
24
|
exports.mapLabels = mapLabels;
|
|
28
25
|
const dispatcher_1 = require("../../protoc/dispatcher");
|
|
29
|
-
const hatchet_error_1 =
|
|
26
|
+
const hatchet_error_1 = require("../../util/errors/hatchet-error");
|
|
30
27
|
const retrier_1 = require("../../util/retrier");
|
|
31
28
|
const version_1 = require("../../version");
|
|
32
29
|
const slot_types_1 = require("../../v1/slot-types");
|
|
@@ -82,7 +79,7 @@ class DispatcherClient {
|
|
|
82
79
|
return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.sendStepActionEvent(event); }), this.logger);
|
|
83
80
|
}
|
|
84
81
|
catch (e) {
|
|
85
|
-
throw
|
|
82
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
86
83
|
}
|
|
87
84
|
});
|
|
88
85
|
}
|
|
@@ -92,7 +89,7 @@ class DispatcherClient {
|
|
|
92
89
|
return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.sendGroupKeyActionEvent(in_); }), this.logger);
|
|
93
90
|
}
|
|
94
91
|
catch (e) {
|
|
95
|
-
throw
|
|
92
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
96
93
|
}
|
|
97
94
|
});
|
|
98
95
|
}
|
|
@@ -112,7 +109,7 @@ class DispatcherClient {
|
|
|
112
109
|
});
|
|
113
110
|
}
|
|
114
111
|
catch (e) {
|
|
115
|
-
throw
|
|
112
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
116
113
|
}
|
|
117
114
|
});
|
|
118
115
|
}
|
|
@@ -125,7 +122,7 @@ class DispatcherClient {
|
|
|
125
122
|
});
|
|
126
123
|
}
|
|
127
124
|
catch (e) {
|
|
128
|
-
throw
|
|
125
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
129
126
|
}
|
|
130
127
|
});
|
|
131
128
|
}
|
|
@@ -13,6 +13,8 @@ const worker_threads_1 = require("worker_threads");
|
|
|
13
13
|
const hatchet_client_1 = require("../../hatchet-client");
|
|
14
14
|
const config_loader_1 = require("../../../util/config-loader");
|
|
15
15
|
const nice_grpc_1 = require("nice-grpc");
|
|
16
|
+
const hatchet_error_1 = require("../../../util/errors/hatchet-error");
|
|
17
|
+
const grpc_error_1 = require("../../../util/grpc-error");
|
|
16
18
|
const grpc_helpers_1 = require("../../../util/grpc-helpers");
|
|
17
19
|
const dispatcher_client_1 = require("../dispatcher-client");
|
|
18
20
|
const heartbeat_controller_1 = require("./heartbeat-controller");
|
|
@@ -69,7 +71,7 @@ class HeartbeatWorker {
|
|
|
69
71
|
this.timeLastHeartbeat = now;
|
|
70
72
|
}
|
|
71
73
|
catch (e) {
|
|
72
|
-
if (e
|
|
74
|
+
if ((0, grpc_error_1.getGrpcErrorCode)(e) === nice_grpc_1.Status.UNIMPLEMENTED) {
|
|
73
75
|
// break out of interval
|
|
74
76
|
const message = 'Heartbeat not implemented, closing heartbeat';
|
|
75
77
|
this.logger.debug(message);
|
|
@@ -80,7 +82,7 @@ class HeartbeatWorker {
|
|
|
80
82
|
this.stop();
|
|
81
83
|
return;
|
|
82
84
|
}
|
|
83
|
-
const message = `Failed to send heartbeat: ${e
|
|
85
|
+
const message = `Failed to send heartbeat: ${(0, hatchet_error_1.getErrorMessage)(e)}`;
|
|
84
86
|
this.logger.debug(message);
|
|
85
87
|
postMessage({
|
|
86
88
|
type: 'error',
|
|
@@ -96,13 +98,14 @@ class HeartbeatWorker {
|
|
|
96
98
|
stop() {
|
|
97
99
|
if (this.heartbeatInterval) {
|
|
98
100
|
clearInterval(this.heartbeatInterval);
|
|
99
|
-
this.heartbeatInterval =
|
|
101
|
+
this.heartbeatInterval = undefined;
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
const heartbeat = new HeartbeatWorker(worker_threads_1.workerData.config, worker_threads_1.workerData.workerId);
|
|
104
106
|
heartbeat.start();
|
|
105
107
|
worker_threads_1.parentPort === null || worker_threads_1.parentPort === void 0 ? void 0 : worker_threads_1.parentPort.on('message', (msg) => {
|
|
106
|
-
if (msg === heartbeat_controller_1.STOP_HEARTBEAT)
|
|
108
|
+
if (msg === heartbeat_controller_1.STOP_HEARTBEAT) {
|
|
107
109
|
heartbeat.stop();
|
|
110
|
+
}
|
|
108
111
|
});
|
|
@@ -17,7 +17,7 @@ export interface PushEventOptions {
|
|
|
17
17
|
}
|
|
18
18
|
export interface EventWithMetadata<T> {
|
|
19
19
|
payload: T;
|
|
20
|
-
additionalMetadata?: Record<string,
|
|
20
|
+
additionalMetadata?: Record<string, unknown>;
|
|
21
21
|
priority?: number;
|
|
22
22
|
scope?: string;
|
|
23
23
|
}
|
|
@@ -31,7 +31,7 @@ export declare class EventClient {
|
|
|
31
31
|
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory, api: HatchetClient['api']);
|
|
32
32
|
push<T>(type: string, input: T, options?: PushEventOptions): Promise<import("../../protoc/events/events").Event>;
|
|
33
33
|
bulkPush<T>(type: string, inputs: EventWithMetadata<T>[], options?: PushEventOptions): Promise<import("../../protoc/events/events").Events>;
|
|
34
|
-
putLog(taskRunExternalId: string, log: string, level?: LogLevel, taskRetryCount?: number, metadata?: Record<string,
|
|
34
|
+
putLog(taskRunExternalId: string, log: string, level?: LogLevel, taskRetryCount?: number, metadata?: Record<string, unknown>): Promise<void>;
|
|
35
35
|
putStream(taskRunExternalId: string, data: string | Uint8Array, index: number | undefined): Promise<void>;
|
|
36
36
|
list(opts?: Parameters<typeof this.api.v1EventList>[1]): Promise<import("../rest/generated/data-contracts").V1EventList>;
|
|
37
37
|
}
|
|
@@ -8,16 +8,12 @@ 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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.EventClient = exports.LogLevel = void 0;
|
|
16
13
|
const events_1 = require("../../protoc/events/events");
|
|
17
|
-
const hatchet_error_1 =
|
|
14
|
+
const hatchet_error_1 = require("../../util/errors/hatchet-error");
|
|
18
15
|
const retrier_1 = require("../../util/retrier");
|
|
19
16
|
const apply_namespace_1 = require("../../util/apply-namespace");
|
|
20
|
-
// eslint-disable-next-line no-shadow
|
|
21
17
|
var LogLevel;
|
|
22
18
|
(function (LogLevel) {
|
|
23
19
|
LogLevel["INFO"] = "INFO";
|
|
@@ -52,7 +48,7 @@ class EventClient {
|
|
|
52
48
|
return e;
|
|
53
49
|
}
|
|
54
50
|
catch (e) {
|
|
55
|
-
throw
|
|
51
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
56
52
|
}
|
|
57
53
|
}
|
|
58
54
|
bulkPush(type, inputs, options = {}) {
|
|
@@ -84,7 +80,7 @@ class EventClient {
|
|
|
84
80
|
return res;
|
|
85
81
|
}
|
|
86
82
|
catch (e) {
|
|
87
|
-
throw
|
|
83
|
+
throw (0, hatchet_error_1.toHatchetError)(e);
|
|
88
84
|
}
|
|
89
85
|
}
|
|
90
86
|
putLog(taskRunExternalId, log, level, taskRetryCount, metadata) {
|
|
@@ -105,8 +101,7 @@ class EventClient {
|
|
|
105
101
|
metadata: metadata ? JSON.stringify(metadata) : undefined,
|
|
106
102
|
})
|
|
107
103
|
.catch((e) => {
|
|
108
|
-
|
|
109
|
-
this.logger.warn(`Could not put log: ${e.message}`);
|
|
104
|
+
this.logger.warn(`Could not put log: ${(0, hatchet_error_1.getErrorMessage)(e)}`);
|
|
110
105
|
});
|
|
111
106
|
});
|
|
112
107
|
}
|
|
@@ -131,8 +126,7 @@ class EventClient {
|
|
|
131
126
|
eventIndex: index,
|
|
132
127
|
});
|
|
133
128
|
}), this.logger).catch((e) => {
|
|
134
|
-
|
|
135
|
-
this.logger.warn(`Could not put log: ${e.message}`);
|
|
129
|
+
this.logger.warn(`Could not put log: ${(0, hatchet_error_1.getErrorMessage)(e)}`);
|
|
136
130
|
});
|
|
137
131
|
});
|
|
138
132
|
}
|
|
@@ -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.HatchetLogger = exports.DEFAULT_LOGGER = void 0;
|
|
13
|
-
/* eslint-disable no-console */
|
|
14
13
|
const logger_1 = require("../../util/logger");
|
|
15
14
|
const DEFAULT_LOGGER = (context, logLevel) => new HatchetLogger(context, logLevel);
|
|
16
15
|
exports.DEFAULT_LOGGER = DEFAULT_LOGGER;
|
|
@@ -20,6 +19,7 @@ class HatchetLogger {
|
|
|
20
19
|
this.context = context;
|
|
21
20
|
}
|
|
22
21
|
log(level, message, color = '37') {
|
|
22
|
+
var _a;
|
|
23
23
|
if (logger_1.LogLevelEnum[level] >= logger_1.LogLevelEnum[this.logLevel]) {
|
|
24
24
|
const time = new Date().toLocaleString('en-US', {
|
|
25
25
|
month: '2-digit',
|
|
@@ -29,22 +29,13 @@ class HatchetLogger {
|
|
|
29
29
|
minute: '2-digit',
|
|
30
30
|
second: '2-digit',
|
|
31
31
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
if (level === 'INFO') {
|
|
41
|
-
print = console.info;
|
|
42
|
-
}
|
|
43
|
-
if (level === 'DEBUG') {
|
|
44
|
-
print = console.debug;
|
|
45
|
-
}
|
|
46
|
-
// eslint-disable-next-line no-console
|
|
47
|
-
print(`🪓 ${process.pid} | ${time} ${color && `\x1b[${color || ''}m`} [${level}/${this.context}] ${message}\x1b[0m`);
|
|
32
|
+
const logFn = {
|
|
33
|
+
ERROR: console.error,
|
|
34
|
+
WARN: console.warn,
|
|
35
|
+
INFO: console.info,
|
|
36
|
+
DEBUG: console.debug,
|
|
37
|
+
};
|
|
38
|
+
((_a = logFn[level]) !== null && _a !== void 0 ? _a : console.log)(`🪓 ${process.pid} | ${time} ${color && `\x1b[${color || ''}m`} [${level}/${this.context}] ${message}\x1b[0m`);
|
|
48
39
|
}
|
|
49
40
|
}
|
|
50
41
|
debug(message) {
|
|
@@ -33,9 +33,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.DurableEventGrpcPooledListener = exports.DurableEventStreamable = void 0;
|
|
36
|
-
// eslint-disable-next-line max-classes-per-file
|
|
37
36
|
const events_1 = require("events");
|
|
38
37
|
const abort_controller_x_1 = require("abort-controller-x");
|
|
38
|
+
const hatchet_error_1 = require("../../../util/errors/hatchet-error");
|
|
39
39
|
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
40
40
|
const abort_error_1 = require("../../../util/abort-error");
|
|
41
41
|
class DurableEventStreamable {
|
|
@@ -53,8 +53,9 @@ class DurableEventStreamable {
|
|
|
53
53
|
return new Promise((resolve, reject) => {
|
|
54
54
|
let cleanedUp = false;
|
|
55
55
|
const cleanup = () => {
|
|
56
|
-
if (cleanedUp)
|
|
56
|
+
if (cleanedUp) {
|
|
57
57
|
return;
|
|
58
|
+
}
|
|
58
59
|
cleanedUp = true;
|
|
59
60
|
this.responseEmitter.removeListener('response', onResponse);
|
|
60
61
|
if (signal) {
|
|
@@ -139,13 +140,13 @@ class DurableEventGrpcPooledListener {
|
|
|
139
140
|
try {
|
|
140
141
|
this.client.logger.debug('Initializing durable-event-listener');
|
|
141
142
|
this.signal = new AbortController();
|
|
142
|
-
// eslint-disable-next-line no-plusplus
|
|
143
143
|
this.currRequester++;
|
|
144
144
|
this.listener = this.client.client.listenForDurableEvent(this.request(), {
|
|
145
145
|
signal: this.signal.signal,
|
|
146
146
|
});
|
|
147
|
-
if (retries > 0)
|
|
147
|
+
if (retries > 0) {
|
|
148
148
|
setTimeout(() => this.replayRequests(), 100);
|
|
149
|
+
}
|
|
149
150
|
try {
|
|
150
151
|
for (var _d = true, _e = __asyncValues(this.listener), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
151
152
|
_c = _f.value;
|
|
@@ -177,7 +178,7 @@ class DurableEventGrpcPooledListener {
|
|
|
177
178
|
this.client.logger.debug('Durable event listener aborted');
|
|
178
179
|
return;
|
|
179
180
|
}
|
|
180
|
-
this.client.logger.error(`Error in durable-event-listener: ${e
|
|
181
|
+
this.client.logger.error(`Error in durable-event-listener: ${(0, hatchet_error_1.getErrorMessage)(e)}`);
|
|
181
182
|
}
|
|
182
183
|
finally {
|
|
183
184
|
const subscriberCount = Object.keys(this.subscribers).length;
|
|
@@ -206,9 +207,9 @@ class DurableEventGrpcPooledListener {
|
|
|
206
207
|
}
|
|
207
208
|
subscribe(request) {
|
|
208
209
|
const { taskId, signalKey } = request;
|
|
209
|
-
if (!this.listener)
|
|
210
|
+
if (!this.listener) {
|
|
210
211
|
throw new Error('listener not initialized');
|
|
211
|
-
|
|
212
|
+
}
|
|
212
213
|
const subscriptionId = (this.subscriptionCounter++).toString();
|
|
213
214
|
const subscriber = new DurableEventStreamable(this.listener, taskId, signalKey, subscriptionId, () => this.cleanupSubscription(subscriptionId));
|
|
214
215
|
this.subscribers[subscriptionId] = subscriber;
|
|
@@ -268,8 +269,9 @@ class DurableEventGrpcPooledListener {
|
|
|
268
269
|
_d = false;
|
|
269
270
|
const e = _c;
|
|
270
271
|
// Stop if this requester is outdated
|
|
271
|
-
if (currRequester !== this.currRequester)
|
|
272
|
+
if (currRequester !== this.currRequester) {
|
|
272
273
|
break;
|
|
274
|
+
}
|
|
273
275
|
const request = e[0];
|
|
274
276
|
const key = keyHelper(request.taskId, request.signalKey);
|
|
275
277
|
// Only send unique subscriptions
|
|
@@ -28,7 +28,7 @@ export declare class RunEventListener {
|
|
|
28
28
|
client: DispatcherClient;
|
|
29
29
|
q: Array<StepRunEvent>;
|
|
30
30
|
eventEmitter: EventEmitter<[never]>;
|
|
31
|
-
pollInterval:
|
|
31
|
+
pollInterval: ReturnType<typeof setInterval> | undefined;
|
|
32
32
|
constructor(client: DispatcherClient);
|
|
33
33
|
static forRunId(workflowRunId: string, client: DispatcherClient): RunEventListener;
|
|
34
34
|
static forAdditionalMeta(key: string, value: string, client: DispatcherClient): RunEventListener;
|
|
@@ -33,8 +33,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.RunListenerClient = exports.RunEventListener = exports.RunEventType = void 0;
|
|
36
|
-
// eslint-disable-next-line max-classes-per-file
|
|
37
36
|
const nice_grpc_1 = require("nice-grpc");
|
|
37
|
+
const grpc_error_1 = require("../../../util/grpc-error");
|
|
38
38
|
const events_1 = require("events");
|
|
39
39
|
const dispatcher_1 = require("../../../protoc/dispatcher");
|
|
40
40
|
const hatchet_error_1 = __importDefault(require("../../../util/errors/hatchet-error"));
|
|
@@ -42,7 +42,6 @@ const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
|
42
42
|
const pooled_child_listener_client_1 = require("./pooled-child-listener-client");
|
|
43
43
|
const DEFAULT_EVENT_LISTENER_RETRY_INTERVAL = 5; // seconds
|
|
44
44
|
const DEFAULT_EVENT_LISTENER_RETRY_COUNT = 5;
|
|
45
|
-
// eslint-disable-next-line no-shadow
|
|
46
45
|
var RunEventType;
|
|
47
46
|
(function (RunEventType) {
|
|
48
47
|
RunEventType["STEP_RUN_EVENT_TYPE_STARTED"] = "STEP_RUN_EVENT_TYPE_STARTED";
|
|
@@ -125,39 +124,45 @@ class RunEventListener {
|
|
|
125
124
|
var _a, e_1, _b, _c;
|
|
126
125
|
var _d;
|
|
127
126
|
let listener = listenerFactory();
|
|
128
|
-
|
|
127
|
+
while (true) {
|
|
129
128
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
129
|
+
try {
|
|
130
|
+
for (var _e = true, listener_1 = (e_1 = void 0, __asyncValues(listener)), listener_1_1; listener_1_1 = yield listener_1.next(), _a = listener_1_1.done, !_a; _e = true) {
|
|
131
|
+
_c = listener_1_1.value;
|
|
132
|
+
_e = false;
|
|
133
|
+
const workflowEvent = _c;
|
|
134
|
+
const eventType = (_d = resourceTypeMap[workflowEvent.resourceType]) === null || _d === void 0 ? void 0 : _d[workflowEvent.eventType];
|
|
135
|
+
if (eventType) {
|
|
136
|
+
this.emit({
|
|
137
|
+
type: eventType,
|
|
138
|
+
payload: workflowEvent.eventPayload,
|
|
139
|
+
resourceId: workflowEvent.resourceId,
|
|
140
|
+
workflowRunId: workflowEvent.workflowRunId,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
146
|
+
finally {
|
|
147
|
+
try {
|
|
148
|
+
if (!_e && !_a && (_b = listener_1.return)) yield _b.call(listener_1);
|
|
149
|
+
}
|
|
150
|
+
finally { if (e_1) throw e_1.error; }
|
|
149
151
|
}
|
|
150
|
-
finally { if (e_1) throw e_1.error; }
|
|
151
|
-
}
|
|
152
|
-
this.eventEmitter.emit('complete');
|
|
153
|
-
}
|
|
154
|
-
catch (e) {
|
|
155
|
-
if (e.code === nice_grpc_1.Status.CANCELLED) {
|
|
156
152
|
this.eventEmitter.emit('complete');
|
|
157
153
|
return;
|
|
158
154
|
}
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
catch (e) {
|
|
156
|
+
if ((0, grpc_error_1.getGrpcErrorCode)(e) === nice_grpc_1.Status.CANCELLED) {
|
|
157
|
+
this.eventEmitter.emit('complete');
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if ((0, grpc_error_1.getGrpcErrorCode)(e) === nice_grpc_1.Status.UNAVAILABLE) {
|
|
161
|
+
listener = yield this.retrySubscribe(listenerFactory);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
throw e;
|
|
165
|
+
}
|
|
161
166
|
}
|
|
162
167
|
}
|
|
163
168
|
});
|
|
@@ -170,7 +175,7 @@ class RunEventListener {
|
|
|
170
175
|
yield (0, sleep_1.default)(DEFAULT_EVENT_LISTENER_RETRY_INTERVAL);
|
|
171
176
|
return listenerFactory();
|
|
172
177
|
}
|
|
173
|
-
catch (
|
|
178
|
+
catch (_a) {
|
|
174
179
|
retries += 1;
|
|
175
180
|
}
|
|
176
181
|
}
|
|
@@ -186,7 +191,6 @@ class RunEventListener {
|
|
|
186
191
|
this.eventEmitter.emit('event');
|
|
187
192
|
});
|
|
188
193
|
try {
|
|
189
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
190
194
|
for (var _d = true, _e = __asyncValues((0, events_1.on)(this.eventEmitter, 'event')), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
|
|
191
195
|
_c = _f.value;
|
|
192
196
|
_d = false;
|
|
@@ -33,10 +33,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.RunGrpcPooledListener = exports.Streamable = void 0;
|
|
36
|
-
// eslint-disable-next-line max-classes-per-file
|
|
37
36
|
const events_1 = require("events");
|
|
38
37
|
const dispatcher_1 = require("../../../protoc/dispatcher");
|
|
39
38
|
const abort_controller_x_1 = require("abort-controller-x");
|
|
39
|
+
const hatchet_error_1 = require("../../../util/errors/hatchet-error");
|
|
40
40
|
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
41
41
|
const abort_error_1 = require("../../../util/abort-error");
|
|
42
42
|
class Streamable {
|
|
@@ -48,8 +48,9 @@ class Streamable {
|
|
|
48
48
|
this.onCleanup = onCleanup;
|
|
49
49
|
}
|
|
50
50
|
cleanupOnce() {
|
|
51
|
-
if (this.cleanedUp)
|
|
51
|
+
if (this.cleanedUp) {
|
|
52
52
|
return;
|
|
53
|
+
}
|
|
53
54
|
this.cleanedUp = true;
|
|
54
55
|
this.onCleanup();
|
|
55
56
|
}
|
|
@@ -137,8 +138,9 @@ class RunGrpcPooledListener {
|
|
|
137
138
|
this.listener = this.client.client.subscribeToWorkflowRuns(this.request(), {
|
|
138
139
|
signal: this.signal.signal,
|
|
139
140
|
});
|
|
140
|
-
if (retries > 0)
|
|
141
|
+
if (retries > 0) {
|
|
141
142
|
setTimeout(() => this.replayRequests(), 100);
|
|
143
|
+
}
|
|
142
144
|
try {
|
|
143
145
|
for (var _d = true, _e = __asyncValues(this.listener), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
144
146
|
_c = _f.value;
|
|
@@ -168,7 +170,7 @@ class RunGrpcPooledListener {
|
|
|
168
170
|
this.client.logger.debug('Child Listener aborted');
|
|
169
171
|
return;
|
|
170
172
|
}
|
|
171
|
-
this.client.logger.error(`Error in child-listener: ${e
|
|
173
|
+
this.client.logger.error(`Error in child-listener: ${(0, hatchet_error_1.getErrorMessage)(e)}`);
|
|
172
174
|
}
|
|
173
175
|
finally {
|
|
174
176
|
// it is possible the server hangs up early,
|
|
@@ -180,8 +182,9 @@ class RunGrpcPooledListener {
|
|
|
180
182
|
});
|
|
181
183
|
}
|
|
182
184
|
subscribe(request) {
|
|
183
|
-
if (!this.listener)
|
|
185
|
+
if (!this.listener) {
|
|
184
186
|
throw new Error('listener not initialized');
|
|
187
|
+
}
|
|
185
188
|
this.subscribers[request.workflowRunId] = new Streamable(this.listener, request.workflowRunId, () => {
|
|
186
189
|
delete this.subscribers[request.workflowRunId];
|
|
187
190
|
});
|