@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
|
@@ -43,11 +43,13 @@ exports.DeprecationError = DeprecationError;
|
|
|
43
43
|
function parseSemver(v) {
|
|
44
44
|
let s = v.startsWith('v') ? v.slice(1) : v;
|
|
45
45
|
const dashIdx = s.indexOf('-');
|
|
46
|
-
if (dashIdx !== -1)
|
|
46
|
+
if (dashIdx !== -1) {
|
|
47
47
|
s = s.slice(0, dashIdx);
|
|
48
|
+
}
|
|
48
49
|
const parts = s.split('.');
|
|
49
|
-
if (parts.length !== 3)
|
|
50
|
+
if (parts.length !== 3) {
|
|
50
51
|
return [0, 0, 0];
|
|
52
|
+
}
|
|
51
53
|
return [parseInt(parts[0], 10) || 0, parseInt(parts[1], 10) || 0, parseInt(parts[2], 10) || 0];
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
@@ -56,10 +58,12 @@ function parseSemver(v) {
|
|
|
56
58
|
function semverLessThan(a, b) {
|
|
57
59
|
const [aMaj, aMin, aPat] = parseSemver(a);
|
|
58
60
|
const [bMaj, bMin, bPat] = parseSemver(b);
|
|
59
|
-
if (aMaj !== bMaj)
|
|
61
|
+
if (aMaj !== bMaj) {
|
|
60
62
|
return aMaj < bMaj;
|
|
61
|
-
|
|
63
|
+
}
|
|
64
|
+
if (aMin !== bMin) {
|
|
62
65
|
return aMin < bMin;
|
|
66
|
+
}
|
|
63
67
|
return aPat < bPat;
|
|
64
68
|
}
|
|
65
69
|
function emitDeprecationNotice(feature, message, start, logger, opts) {
|
|
@@ -18,8 +18,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.LegacyDualWorker = void 0;
|
|
20
20
|
exports.isLegacyEngine = isLegacyEngine;
|
|
21
|
-
/* eslint-disable no-underscore-dangle */
|
|
22
21
|
const nice_grpc_1 = require("nice-grpc");
|
|
22
|
+
const grpc_error_1 = require("../../../../util/grpc-error");
|
|
23
23
|
const declaration_1 = require("../../../declaration");
|
|
24
24
|
const legacy_v1_worker_1 = require("./legacy-v1-worker");
|
|
25
25
|
const deprecation_1 = require("./deprecation");
|
|
@@ -54,7 +54,7 @@ function isLegacyEngine(v1) {
|
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
56
|
catch (e) {
|
|
57
|
-
if ((
|
|
57
|
+
if ((0, grpc_error_1.getGrpcErrorCode)(e) === nice_grpc_1.Status.UNIMPLEMENTED) {
|
|
58
58
|
const logger = v1.config.logger('Worker', v1.config.log_level);
|
|
59
59
|
(0, deprecation_1.emitDeprecationNotice)('legacy-engine', LEGACY_ENGINE_MESSAGE, LEGACY_ENGINE_START, logger, {
|
|
60
60
|
errorDays: 180,
|
|
@@ -65,8 +65,8 @@ class HealthServer {
|
|
|
65
65
|
}
|
|
66
66
|
initializeMetrics() {
|
|
67
67
|
try {
|
|
68
|
-
//
|
|
69
|
-
// eslint-disable-next-line
|
|
68
|
+
// THIS IS AN OPTIONAL DEPENDENCY
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
70
70
|
const { Registry, Gauge, collectDefaultMetrics } = require('prom-client');
|
|
71
71
|
this.register = new Registry();
|
|
72
72
|
collectDefaultMetrics({ register: this.register });
|
|
@@ -96,7 +96,7 @@ class HealthServer {
|
|
|
96
96
|
});
|
|
97
97
|
this.metricsInitialized = true;
|
|
98
98
|
}
|
|
99
|
-
catch (
|
|
99
|
+
catch (_a) {
|
|
100
100
|
this.metricsInitialized = false;
|
|
101
101
|
this.logger.error('Metrics initialization failed - prom-client dependency not installed');
|
|
102
102
|
}
|
|
@@ -28,7 +28,6 @@ function resolveWorkerOptions(options) {
|
|
|
28
28
|
(slotConfig[slot_types_1.SlotType.Default] != null ? slotConfig[slot_types_1.SlotType.Default] : undefined), durableSlots: options.durableSlots ||
|
|
29
29
|
(slotConfig[slot_types_1.SlotType.Durable] != null ? slotConfig[slot_types_1.SlotType.Durable] : undefined), slotConfig });
|
|
30
30
|
}
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
32
31
|
exports.testingExports = {
|
|
33
32
|
resolveWorkerOptions,
|
|
34
33
|
};
|
|
@@ -49,12 +48,10 @@ function getRequiredSlotTypes(workflows) {
|
|
|
49
48
|
};
|
|
50
49
|
for (const wf of workflows) {
|
|
51
50
|
if (wf instanceof declaration_1.BaseWorkflowDeclaration) {
|
|
52
|
-
// eslint-disable-next-line dot-notation
|
|
53
51
|
const tasks = wf.definition['_tasks'];
|
|
54
52
|
for (const task of tasks) {
|
|
55
53
|
addFromRequests(task.slotRequests, slot_types_1.SlotType.Default);
|
|
56
54
|
}
|
|
57
|
-
// eslint-disable-next-line dot-notation
|
|
58
55
|
const durableTasks = wf.definition['_durableTasks'];
|
|
59
56
|
if (durableTasks.length > 0) {
|
|
60
57
|
required.add(slot_types_1.SlotType.Durable);
|
|
@@ -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) {
|
|
@@ -21,11 +54,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
21
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
55
|
exports.InternalWorker = void 0;
|
|
23
56
|
exports.mapRateLimitPb = mapRateLimitPb;
|
|
24
|
-
/* eslint-disable no-underscore-dangle */
|
|
25
|
-
/* eslint-disable no-nested-ternary */
|
|
26
57
|
const hatchet_error_1 = __importDefault(require("../../../util/errors/hatchet-error"));
|
|
27
58
|
const dispatcher_1 = require("../../../protoc/dispatcher");
|
|
28
|
-
const hatchet_promise_1 =
|
|
59
|
+
const hatchet_promise_1 = __importStar(require("../../../util/hatchet-promise/hatchet-promise"));
|
|
29
60
|
const workflows_1 = require("../../../protoc/workflows");
|
|
30
61
|
const logger_1 = require("../../../util/logger");
|
|
31
62
|
const task_1 = require("../../task");
|
|
@@ -217,7 +248,6 @@ class InternalWorker {
|
|
|
217
248
|
// Convert Zod schema to JSON Schema if provided
|
|
218
249
|
let inputJsonSchema;
|
|
219
250
|
if (workflow.inputValidator) {
|
|
220
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
221
251
|
const jsonSchema = (0, zod_to_json_schema_1.zodToJsonSchema)(workflow.inputValidator);
|
|
222
252
|
inputJsonSchema = new TextEncoder().encode(JSON.stringify(jsonSchema));
|
|
223
253
|
}
|
|
@@ -570,7 +600,7 @@ class InternalWorker {
|
|
|
570
600
|
// where the main action handler isn't currently awaiting `future.promise`.
|
|
571
601
|
future.promise.catch(() => undefined);
|
|
572
602
|
// Cancel the future (rejects the wrapper); user code must still cooperate with AbortSignal.
|
|
573
|
-
future.cancel(
|
|
603
|
+
future.cancel(hatchet_promise_1.CancellationReason.CANCELLED_BY_WORKER);
|
|
574
604
|
// Track completion of the underlying work (not the cancelable wrapper).
|
|
575
605
|
// Ensure this promise never throws into our supervision flow.
|
|
576
606
|
const completion = ((_c = future.inner) !== null && _c !== void 0 ? _c : future.promise).catch(() => undefined);
|
|
@@ -791,15 +821,15 @@ function isLeafTask(task, allTasks) {
|
|
|
791
821
|
return !allTasks.some((t) => { var _a; return (_a = t.parents) === null || _a === void 0 ? void 0 : _a.some((p) => p.name === task.name); });
|
|
792
822
|
}
|
|
793
823
|
function mapRateLimitPb(limits) {
|
|
794
|
-
if (!limits)
|
|
824
|
+
if (!limits) {
|
|
795
825
|
return [];
|
|
826
|
+
}
|
|
796
827
|
return limits.map((l) => {
|
|
797
828
|
let key = l.staticKey;
|
|
798
829
|
const keyExpression = l.dynamicKey;
|
|
799
830
|
if (l.key !== undefined) {
|
|
800
|
-
// eslint-disable-next-line no-console
|
|
801
831
|
console.warn('key is deprecated and will be removed in a future release, please use staticKey instead');
|
|
802
|
-
key = l
|
|
832
|
+
({ key } = l);
|
|
803
833
|
}
|
|
804
834
|
if (keyExpression !== undefined) {
|
|
805
835
|
if (key !== undefined) {
|
|
@@ -816,7 +846,7 @@ function mapRateLimitPb(limits) {
|
|
|
816
846
|
let units;
|
|
817
847
|
let unitsExpression;
|
|
818
848
|
if (typeof l.units === 'number') {
|
|
819
|
-
units = l
|
|
849
|
+
({ units } = l);
|
|
820
850
|
}
|
|
821
851
|
else {
|
|
822
852
|
if (!validateCelExpression(l.units)) {
|
|
@@ -853,7 +883,6 @@ function mapRateLimitPb(limits) {
|
|
|
853
883
|
});
|
|
854
884
|
}
|
|
855
885
|
// Helper function to validate CEL expressions
|
|
856
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
857
886
|
function validateCelExpression(_expr) {
|
|
858
887
|
// FIXME: this is a placeholder. In a real implementation, you'd need to use a CEL parser or validator.
|
|
859
888
|
// For now, we'll just return true to mimic the behavior.
|
|
@@ -163,8 +163,9 @@ class Worker {
|
|
|
163
163
|
const pollInterval = 200;
|
|
164
164
|
const start = Date.now();
|
|
165
165
|
while (Date.now() - start < timeoutMs) {
|
|
166
|
-
if ((_a = this._internal) === null || _a === void 0 ? void 0 : _a.workerId)
|
|
166
|
+
if ((_a = this._internal) === null || _a === void 0 ? void 0 : _a.workerId) {
|
|
167
167
|
return;
|
|
168
|
+
}
|
|
168
169
|
yield (0, sleep_1.default)(pollInterval);
|
|
169
170
|
}
|
|
170
171
|
throw new Error(`Worker ${this.name} did not become ready within ${timeoutMs}ms`);
|
package/v1/conditions/base.js
CHANGED
package/v1/conditions/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable no-param-reassign */
|
|
3
|
-
/* eslint-disable no-shadow */
|
|
4
|
-
/* eslint-disable max-classes-per-file */
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.OrCondition = exports.UserEventCondition = exports.SleepCondition = void 0;
|
|
7
4
|
exports.Render = Render;
|
|
@@ -33,8 +30,9 @@ exports.OrCondition = OrCondition;
|
|
|
33
30
|
* );
|
|
34
31
|
*/
|
|
35
32
|
function Render(action, conditions) {
|
|
36
|
-
if (!conditions)
|
|
33
|
+
if (!conditions) {
|
|
37
34
|
return [];
|
|
35
|
+
}
|
|
38
36
|
if (!Array.isArray(conditions)) {
|
|
39
37
|
return Render(action, [conditions]);
|
|
40
38
|
}
|
package/v1/declaration.d.ts
CHANGED
|
@@ -453,7 +453,7 @@ export declare class WorkflowDeclaration<I extends InputType = UnknownInputType,
|
|
|
453
453
|
* @template MiddlewareBefore - Extra fields added to the task fn input by pre-middleware hooks.
|
|
454
454
|
* @template MiddlewareAfter - Extra fields merged into the task output by post-middleware hooks.
|
|
455
455
|
*/
|
|
456
|
-
export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputType, O extends OutputType = void, GlobalInput extends Record<string, any> = {}, GlobalOutput extends Record<string, any> = {},
|
|
456
|
+
export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputType, O extends OutputType = void, GlobalInput extends Record<string, any> = {}, GlobalOutput extends Record<string, any> = {}, _MiddlewareBefore extends Record<string, any> = {}, MiddlewareAfter extends Record<string, any> = {}> extends BaseWorkflowDeclaration<I, O> {
|
|
457
457
|
_standalone_task_name: string;
|
|
458
458
|
constructor(options: CreateTaskWorkflowOpts<any, any>, client?: IHatchetClient);
|
|
459
459
|
/**
|
package/v1/declaration.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `Runnables` in the Hatchet TypeScript SDK are things that can be run, namely tasks and workflows. The two main types of runnables you'll encounter are:
|
|
4
|
+
*
|
|
5
|
+
* - `WorkflowDeclaration`, returned by `hatchet.workflow(...)`, which lets you define tasks and call `run()`, `schedule()`, `cron()`, etc.
|
|
6
|
+
* - `TaskWorkflowDeclaration`, returned by `hatchet.task(...)`, which is a single standalone task that exposes the same execution helpers as a workflow.
|
|
7
|
+
* @module Runnables
|
|
8
|
+
*/
|
|
2
9
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
10
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
11
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -16,7 +23,6 @@ exports.CreateDurableTaskWorkflow = CreateDurableTaskWorkflow;
|
|
|
16
23
|
const abort_error_1 = require("../util/abort-error");
|
|
17
24
|
const parent_run_context_vars_1 = require("./parent-run-context-vars");
|
|
18
25
|
const UNBOUND_ERR = new Error('workflow unbound to hatchet client, hint: use client.run instead');
|
|
19
|
-
// eslint-disable-next-line no-shadow
|
|
20
26
|
var Priority;
|
|
21
27
|
(function (Priority) {
|
|
22
28
|
Priority[Priority["LOW"] = 1] = "LOW";
|
|
@@ -93,15 +99,12 @@ class BaseWorkflowDeclaration {
|
|
|
93
99
|
resp.forEach((ref, index) => {
|
|
94
100
|
const wf = input[index].workflow;
|
|
95
101
|
if (wf instanceof TaskWorkflowDeclaration) {
|
|
96
|
-
// eslint-disable-next-line no-param-reassign
|
|
97
102
|
ref._standaloneTaskName = wf._standalone_task_name;
|
|
98
103
|
}
|
|
99
104
|
if (_standaloneTaskName) {
|
|
100
|
-
// eslint-disable-next-line no-param-reassign
|
|
101
105
|
ref._standaloneTaskName = _standaloneTaskName;
|
|
102
106
|
}
|
|
103
107
|
// Ensure result subscriptions inherit cancellation if no signal is provided explicitly.
|
|
104
|
-
// eslint-disable-next-line no-param-reassign
|
|
105
108
|
ref.defaultSignal = inheritedSignal;
|
|
106
109
|
res.push(ref);
|
|
107
110
|
});
|
|
@@ -136,11 +139,13 @@ class BaseWorkflowDeclaration {
|
|
|
136
139
|
if (options === null || options === void 0 ? void 0 : options.returnExceptions) {
|
|
137
140
|
const settled = yield Promise.allSettled(refs.map((ref) => ref.result()));
|
|
138
141
|
return settled.map((s) => {
|
|
139
|
-
if (s.status === 'fulfilled')
|
|
142
|
+
if (s.status === 'fulfilled') {
|
|
140
143
|
return s.value;
|
|
144
|
+
}
|
|
141
145
|
const { reason } = s;
|
|
142
|
-
if (reason instanceof Error)
|
|
146
|
+
if (reason instanceof Error) {
|
|
143
147
|
return reason;
|
|
148
|
+
}
|
|
144
149
|
return new Error(Array.isArray(reason) ? reason.join('; ') : String(reason));
|
|
145
150
|
});
|
|
146
151
|
}
|
|
@@ -567,7 +572,7 @@ function CreateDurableTaskWorkflow(options, client) {
|
|
|
567
572
|
const taskWorkflow = new TaskWorkflowDeclaration(options, client);
|
|
568
573
|
// Move the task from tasks to durableTasks
|
|
569
574
|
if (taskWorkflow.definition._tasks.length > 0) {
|
|
570
|
-
const task = taskWorkflow.definition._tasks
|
|
575
|
+
const [task] = taskWorkflow.definition._tasks;
|
|
571
576
|
taskWorkflow.definition._tasks = [];
|
|
572
577
|
taskWorkflow.definition._durableTasks.push(task);
|
|
573
578
|
}
|
|
@@ -47,8 +47,9 @@ function startWorker(_a) {
|
|
|
47
47
|
}
|
|
48
48
|
function stopWorker(worker) {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
if (!worker)
|
|
50
|
+
if (!worker) {
|
|
51
51
|
return;
|
|
52
|
+
}
|
|
52
53
|
yield worker.stop();
|
|
53
54
|
yield (0, sleep_1.default)(300);
|
|
54
55
|
});
|
|
@@ -56,11 +57,11 @@ function stopWorker(worker) {
|
|
|
56
57
|
function poll(fn_1, _a) {
|
|
57
58
|
return __awaiter(this, arguments, void 0, function* (fn, { timeoutMs = 30000, intervalMs = 100, shouldStop, label = 'poll', }) {
|
|
58
59
|
const start = Date.now();
|
|
59
|
-
// eslint-disable-next-line no-constant-condition
|
|
60
60
|
while (true) {
|
|
61
61
|
const value = yield fn();
|
|
62
|
-
if (shouldStop(value))
|
|
62
|
+
if (shouldStop(value)) {
|
|
63
63
|
return value;
|
|
64
|
+
}
|
|
64
65
|
if (Date.now() - start > timeoutMs) {
|
|
65
66
|
throw new Error(`Timed out waiting for ${label} after ${timeoutMs}ms`);
|
|
66
67
|
}
|
|
@@ -20,7 +20,6 @@ workflow.task({
|
|
|
20
20
|
name: 'step1',
|
|
21
21
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
22
|
const results = [];
|
|
23
|
-
// eslint-disable-next-line no-plusplus
|
|
24
23
|
for (let i = 0; i < 50; i++) {
|
|
25
24
|
const result = yield childWorkflow.run({});
|
|
26
25
|
results.push(result);
|
|
@@ -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.bulkReplayTest3 = exports.bulkReplayTest2 = exports.bulkReplayTest1 = void 0;
|
|
13
|
-
/* eslint-disable no-console */
|
|
14
13
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
14
|
exports.bulkReplayTest1 = hatchet_client_1.hatchet.task({
|
|
16
15
|
name: 'bulk-replay-test-1',
|
|
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
/* eslint-disable no-console */
|
|
16
15
|
// > Running a Task with Results
|
|
17
16
|
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
18
17
|
const cancellation_workflow_1 = require("./cancellation-workflow");
|
|
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
/* eslint-disable no-console */
|
|
16
15
|
// > Running a Task with Results
|
|
17
16
|
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
18
17
|
const workflow_1 = require("./workflow");
|
|
@@ -15,7 +15,6 @@ function main() {
|
|
|
15
15
|
const res = yield workflow_1.parent.run({
|
|
16
16
|
N: 10,
|
|
17
17
|
});
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
18
|
console.log(res.Result);
|
|
20
19
|
});
|
|
21
20
|
}
|
|
@@ -23,7 +22,6 @@ if (require.main === module) {
|
|
|
23
22
|
main()
|
|
24
23
|
.then(() => process.exit(0))
|
|
25
24
|
.catch((error) => {
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
25
|
console.error('Error:', error);
|
|
28
26
|
process.exit(1);
|
|
29
27
|
});
|
|
@@ -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.withErrorHandling = exports.parentSingleChild = exports.parent = exports.child = void 0;
|
|
13
|
-
/* eslint-disable no-plusplus */
|
|
14
13
|
// > Declaring a Child
|
|
15
14
|
const hatchet_client_1 = require("../hatchet-client");
|
|
16
15
|
exports.child = hatchet_client_1.hatchet.task({
|
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
/* eslint-disable no-plusplus */
|
|
13
12
|
const hatchet_client_1 = require("../hatchet-client");
|
|
14
13
|
const workflow_1 = require("./workflow");
|
|
15
14
|
function generateRandomString(length) {
|
|
@@ -26,11 +26,8 @@ function main() {
|
|
|
26
26
|
GroupKey: 'B',
|
|
27
27
|
},
|
|
28
28
|
]);
|
|
29
|
-
// eslint-disable-next-line no-console
|
|
30
29
|
console.log(res[0]['to-lower'].TransformedMessage);
|
|
31
|
-
// eslint-disable-next-line no-console
|
|
32
30
|
console.log(res[1]['to-lower'].TransformedMessage);
|
|
33
|
-
// eslint-disable-next-line no-console
|
|
34
31
|
console.log(res[2]['to-lower'].TransformedMessage);
|
|
35
32
|
});
|
|
36
33
|
}
|
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
/* eslint-disable no-plusplus */
|
|
13
12
|
const hatchet_client_1 = require("../hatchet-client");
|
|
14
13
|
const workflow_1 = require("./workflow");
|
|
15
14
|
function generateRandomString(length) {
|
|
@@ -26,11 +26,8 @@ function main() {
|
|
|
26
26
|
GroupKey: 'B',
|
|
27
27
|
},
|
|
28
28
|
]);
|
|
29
|
-
// eslint-disable-next-line no-console
|
|
30
29
|
console.log(res[0]['to-lower'].TransformedMessage);
|
|
31
|
-
// eslint-disable-next-line no-console
|
|
32
30
|
console.log(res[1]['to-lower'].TransformedMessage);
|
|
33
|
-
// eslint-disable-next-line no-console
|
|
34
31
|
console.log(res[2]['to-lower'].TransformedMessage);
|
|
35
32
|
});
|
|
36
33
|
}
|
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
/* eslint-disable no-console */
|
|
13
12
|
const workflow_1 = require("./workflow");
|
|
14
13
|
function main() {
|
|
15
14
|
return __awaiter(this, void 0, void 0, function* () {
|
package/v1/examples/dag/run.js
CHANGED
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
/* eslint-disable no-console */
|
|
13
12
|
const workflow_1 = require("./workflow");
|
|
14
13
|
function main() {
|
|
15
14
|
return __awaiter(this, void 0, void 0, function* () {
|
package/v1/examples/deep/run.js
CHANGED
|
@@ -16,13 +16,11 @@ function main() {
|
|
|
16
16
|
Message: 'hello',
|
|
17
17
|
N: 5,
|
|
18
18
|
});
|
|
19
|
-
// eslint-disable-next-line no-console
|
|
20
19
|
console.log(res.parent.Sum);
|
|
21
20
|
});
|
|
22
21
|
}
|
|
23
22
|
if (require.main === module) {
|
|
24
23
|
main()
|
|
25
|
-
// eslint-disable-next-line no-console
|
|
26
24
|
.catch(console.error)
|
|
27
25
|
.finally(() => process.exit(0));
|
|
28
26
|
}
|
|
@@ -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.waitForSleepTwice = exports.durableWorkflow = exports.SLEEP_TIME = exports.SLEEP_TIME_SECONDS = exports.EVENT_KEY = void 0;
|
|
13
|
-
/* eslint-disable no-console */
|
|
14
13
|
const conditions_1 = require("../../conditions");
|
|
15
14
|
const hatchet_client_1 = require("../hatchet-client");
|
|
16
15
|
exports.EVENT_KEY = 'durable-example:event';
|
|
@@ -45,10 +44,10 @@ function extractKeyAndEventId(waitResult) {
|
|
|
45
44
|
// The shape is typically `{ [readableDataKey]: { [eventId]: ... } }`.
|
|
46
45
|
const obj = waitResult;
|
|
47
46
|
if (obj && typeof obj === 'object') {
|
|
48
|
-
const key = Object.keys(obj)
|
|
47
|
+
const [key] = Object.keys(obj);
|
|
49
48
|
const inner = obj[key];
|
|
50
49
|
if (inner && typeof inner === 'object') {
|
|
51
|
-
const eventId = Object.keys(inner)
|
|
50
|
+
const [eventId] = Object.keys(inner);
|
|
52
51
|
if (eventId) {
|
|
53
52
|
return { key: 'CREATE', eventId };
|
|
54
53
|
}
|
|
@@ -15,7 +15,6 @@ function main() {
|
|
|
15
15
|
const timeStart = Date.now();
|
|
16
16
|
const res = yield workflow_1.durableEvent.run({});
|
|
17
17
|
const timeEnd = Date.now();
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
18
|
console.log(`Time taken: ${timeEnd - timeStart}ms`);
|
|
20
19
|
});
|
|
21
20
|
}
|
|
@@ -23,7 +22,6 @@ if (require.main === module) {
|
|
|
23
22
|
main()
|
|
24
23
|
.then(() => process.exit(0))
|
|
25
24
|
.catch((error) => {
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
25
|
console.error('Error:', error);
|
|
28
26
|
process.exit(1);
|
|
29
27
|
});
|
|
@@ -15,7 +15,6 @@ function main() {
|
|
|
15
15
|
const timeStart = Date.now();
|
|
16
16
|
const res = yield workflow_1.durableSleep.run({});
|
|
17
17
|
const timeEnd = Date.now();
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
18
|
console.log(`Time taken: ${timeEnd - timeStart}ms`);
|
|
20
19
|
});
|
|
21
20
|
}
|
|
@@ -23,7 +22,6 @@ if (require.main === module) {
|
|
|
23
22
|
main()
|
|
24
23
|
.then(() => process.exit(0))
|
|
25
24
|
.catch((error) => {
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
25
|
console.error('Error:', error);
|
|
28
26
|
process.exit(1);
|
|
29
27
|
});
|
|
@@ -15,7 +15,6 @@ function main() {
|
|
|
15
15
|
const timeStart = Date.now();
|
|
16
16
|
const res = yield workflow_1.durableEvent.run({});
|
|
17
17
|
const timeEnd = Date.now();
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
18
|
console.log(`Time taken: ${timeEnd - timeStart}ms`);
|
|
20
19
|
});
|
|
21
20
|
}
|
|
@@ -23,7 +22,6 @@ if (require.main === module) {
|
|
|
23
22
|
main()
|
|
24
23
|
.then(() => process.exit(0))
|
|
25
24
|
.catch((error) => {
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
25
|
console.error('Error:', error);
|
|
28
26
|
process.exit(1);
|
|
29
27
|
});
|
|
@@ -15,7 +15,6 @@ function main() {
|
|
|
15
15
|
const timeStart = Date.now();
|
|
16
16
|
const res = yield workflow_1.durableSleep.run({});
|
|
17
17
|
const timeEnd = Date.now();
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
18
|
console.log(`Time taken: ${timeEnd - timeStart}ms`);
|
|
20
19
|
});
|
|
21
20
|
}
|
|
@@ -23,7 +22,6 @@ if (require.main === module) {
|
|
|
23
22
|
main()
|
|
24
23
|
.then(() => process.exit(0))
|
|
25
24
|
.catch((error) => {
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
25
|
console.error('Error:', error);
|
|
28
26
|
process.exit(1);
|
|
29
27
|
});
|
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
/* eslint-disable no-console */
|
|
13
12
|
const workflow_with_child_1 = require("./workflow-with-child");
|
|
14
13
|
function main() {
|
|
15
14
|
return __awaiter(this, void 0, void 0, function* () {
|