@hatchet-dev/typescript-sdk 1.36.0 → 1.38.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/Api.d.ts +59 -1
- package/clients/rest/generated/Api.js +10 -0
- package/clients/rest/generated/data-contracts.d.ts +7 -0
- package/package.json +1 -1
- package/protoc/dispatcher/dispatcher.d.ts +4 -0
- package/protoc/dispatcher/dispatcher.js +42 -2
- package/protoc/v1/streams.d.ts +18 -0
- package/protoc/v1/streams.js +115 -1
- package/protoc-es/dispatcher/dispatcher_pb.d.ts +12 -0
- package/protoc-es/dispatcher/dispatcher_pb.js +1 -1
- package/protoc-es/v1/streams_pb.d.ts +35 -0
- package/protoc-es/v1/streams_pb.js +12 -2
- package/v1/client/duration.js +3 -3
- package/v1/client/features/streams.d.ts +10 -1
- package/v1/client/features/streams.js +15 -1
- package/v1/client/worker/engine-version.d.ts +2 -0
- package/v1/client/worker/engine-version.js +7 -0
- package/v1/client/worker/worker-internal.d.ts +2 -0
- package/v1/client/worker/worker-internal.js +20 -1
- package/v1/examples/durable-streams/run.d.ts +6 -0
- package/v1/examples/durable-streams/run.js +192 -0
- package/v1/examples/durable-streams/worker.d.ts +1 -0
- package/v1/examples/durable-streams/worker.js +24 -0
- package/v1/examples/durable-streams/workflow.d.ts +9 -0
- package/v1/examples/durable-streams/workflow.js +47 -0
- package/v1/examples/e2e-worker.js +59 -53
- package/v1/examples/retry_after/run.d.ts +1 -0
- package/v1/examples/retry_after/run.js +21 -0
- package/v1/examples/retry_after/worker.d.ts +1 -0
- package/v1/examples/retry_after/worker.js +24 -0
- package/v1/examples/retry_after/workflow.d.ts +9 -0
- package/v1/examples/retry_after/workflow.js +40 -0
- package/v1/task.d.ts +13 -0
- package/v1/task.js +14 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -57,7 +57,16 @@ export declare class StreamsClient {
|
|
|
57
57
|
*/
|
|
58
58
|
topicMetadata(topic: string, options?: Pick<StreamCallOptions, 'namespace'>): Promise<StreamTopicMetadata>;
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
60
|
+
* Makes events() calls without a cursor start after the topic's latest
|
|
61
|
+
* message. Readers already iterating, and any call with a cursor, are
|
|
62
|
+
* unaffected.
|
|
63
|
+
* @param topic - the topic to reset
|
|
64
|
+
* @param options - optional namespace override
|
|
65
|
+
*/
|
|
66
|
+
reset(topic: string, options?: Pick<StreamCallOptions, 'namespace'>): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Yields topic's messages after options.cursor, or from the oldest retained
|
|
69
|
+
* (or, once the topic is reset, after the reset).
|
|
61
70
|
* If the connection drops, it resubscribes from the last message yielded, so
|
|
62
71
|
* nothing is skipped or repeated. Ends when the server hangs up an idle
|
|
63
72
|
* subscription, options.signal aborts, or the caller stops iterating; throws
|
|
@@ -216,7 +216,21 @@ class StreamsClient {
|
|
|
216
216
|
});
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
219
|
-
*
|
|
219
|
+
* Makes events() calls without a cursor start after the topic's latest
|
|
220
|
+
* message. Readers already iterating, and any call with a cursor, are
|
|
221
|
+
* unaffected.
|
|
222
|
+
* @param topic - the topic to reset
|
|
223
|
+
* @param options - optional namespace override
|
|
224
|
+
*/
|
|
225
|
+
reset(topic, options) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
var _a;
|
|
228
|
+
yield this.grpc.reset({ namespace: (_a = options === null || options === void 0 ? void 0 : options.namespace) !== null && _a !== void 0 ? _a : '', topic });
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Yields topic's messages after options.cursor, or from the oldest retained
|
|
233
|
+
* (or, once the topic is reset, after the reset).
|
|
220
234
|
* If the connection drops, it resubscribes from the last message yielded, so
|
|
221
235
|
* nothing is skipped or repeated. Ends when the server hangs up an idle
|
|
222
236
|
* subscription, options.signal aborts, or the caller stops iterating; throws
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const MinEngineVersion: {
|
|
2
2
|
readonly SLOT_CONFIG: "v0.78.23";
|
|
3
3
|
readonly DURABLE_EVICTION: "v0.80.0";
|
|
4
|
+
readonly RETRY_AFTER: "v0.111.0";
|
|
4
5
|
};
|
|
6
|
+
export declare function supportsRetryAfter(engineVersion: string | undefined): boolean;
|
|
5
7
|
export declare function supportsEviction(engineVersion: string | undefined): boolean;
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MinEngineVersion = void 0;
|
|
4
|
+
exports.supportsRetryAfter = supportsRetryAfter;
|
|
4
5
|
exports.supportsEviction = supportsEviction;
|
|
5
6
|
const deprecation_1 = require("./deprecated/deprecation");
|
|
6
7
|
exports.MinEngineVersion = {
|
|
7
8
|
SLOT_CONFIG: 'v0.78.23',
|
|
8
9
|
DURABLE_EVICTION: 'v0.80.0',
|
|
10
|
+
RETRY_AFTER: 'v0.111.0',
|
|
9
11
|
};
|
|
12
|
+
function supportsRetryAfter(engineVersion) {
|
|
13
|
+
if (!engineVersion)
|
|
14
|
+
return false;
|
|
15
|
+
return !(0, deprecation_1.semverLessThan)(engineVersion, exports.MinEngineVersion.RETRY_AFTER);
|
|
16
|
+
}
|
|
10
17
|
function supportsEviction(engineVersion) {
|
|
11
18
|
if (!engineVersion)
|
|
12
19
|
return false;
|
|
@@ -69,6 +69,7 @@ export declare class InternalWorker {
|
|
|
69
69
|
* Keep the signature in sync with the instrumentor wrapper.
|
|
70
70
|
*/
|
|
71
71
|
handleStartStepRun(action: Action): Promise<Error | undefined>;
|
|
72
|
+
private retryAfterMs;
|
|
72
73
|
getStepActionEvent(action: Action, eventType: StepActionEventType, shouldNotRetry: boolean, payload?: any, retryCount?: number): StepActionEvent;
|
|
73
74
|
/**
|
|
74
75
|
* Handles a START_BATCH action: invokes the registered batch task handler once with
|
|
@@ -88,6 +89,7 @@ export declare class InternalWorker {
|
|
|
88
89
|
getBatchActionEvent(action: Action, eventType: StepActionEventType, items: {
|
|
89
90
|
taskRunExternalId: string;
|
|
90
91
|
eventPayload: string;
|
|
92
|
+
retryAfterMs?: number;
|
|
91
93
|
}[]): BatchActionEvent;
|
|
92
94
|
getGroupKeyActionEvent(action: Action, eventType: GroupKeyActionEventType, payload?: any): GroupKeyActionEvent;
|
|
93
95
|
/**
|
|
@@ -349,6 +349,7 @@ class InternalWorker {
|
|
|
349
349
|
});
|
|
350
350
|
const failure = (error) => __awaiter(this, void 0, void 0, function* () {
|
|
351
351
|
const shouldNotRetry = error instanceof task_1.NonRetryableError;
|
|
352
|
+
const retryAfterMs = this.retryAfterMs(error, actionId);
|
|
352
353
|
try {
|
|
353
354
|
if (context.cancelled) {
|
|
354
355
|
return;
|
|
@@ -366,6 +367,7 @@ class InternalWorker {
|
|
|
366
367
|
message: error === null || error === void 0 ? void 0 : error.message,
|
|
367
368
|
stack: error === null || error === void 0 ? void 0 : error.stack,
|
|
368
369
|
}, action.retryCount);
|
|
370
|
+
event.retryAfterMs = retryAfterMs;
|
|
369
371
|
yield this.client.dispatcher.sendStepActionEvent(event);
|
|
370
372
|
}
|
|
371
373
|
catch (e) {
|
|
@@ -423,6 +425,18 @@ class InternalWorker {
|
|
|
423
425
|
}
|
|
424
426
|
});
|
|
425
427
|
}
|
|
428
|
+
retryAfterMs(error, actionId) {
|
|
429
|
+
var _a;
|
|
430
|
+
if (!(error instanceof task_1.RetryAfterError)) {
|
|
431
|
+
return undefined;
|
|
432
|
+
}
|
|
433
|
+
if (!(0, engine_version_1.supportsRetryAfter)(this.engineVersion)) {
|
|
434
|
+
this.logger.warn(`RetryAfterError requires engine >= ${engine_version_1.MinEngineVersion.RETRY_AFTER} ` +
|
|
435
|
+
`(connected: ${(_a = this.engineVersion) !== null && _a !== void 0 ? _a : 'unknown'}). Task ${actionId} threw it, so the engine ` +
|
|
436
|
+
`will handle the failure with the task's retry policy instead of the requested delay.`);
|
|
437
|
+
}
|
|
438
|
+
return error.afterMs;
|
|
439
|
+
}
|
|
426
440
|
getStepActionEvent(action, eventType, shouldNotRetry, payload = '', retryCount = 0) {
|
|
427
441
|
return {
|
|
428
442
|
workerId: this.name,
|
|
@@ -518,7 +532,12 @@ class InternalWorker {
|
|
|
518
532
|
sendBatchFailureForAll(action, memberIds, error) {
|
|
519
533
|
return __awaiter(this, void 0, void 0, function* () {
|
|
520
534
|
const payload = JSON.stringify({ message: error === null || error === void 0 ? void 0 : error.message, stack: error === null || error === void 0 ? void 0 : error.stack });
|
|
521
|
-
const
|
|
535
|
+
const retryAfterMs = this.retryAfterMs(error, action.actionId);
|
|
536
|
+
const items = memberIds.map((id) => ({
|
|
537
|
+
taskRunExternalId: id,
|
|
538
|
+
eventPayload: payload,
|
|
539
|
+
retryAfterMs,
|
|
540
|
+
}));
|
|
522
541
|
try {
|
|
523
542
|
yield this.client.dispatcher.sendBatchActionEvent(this.getBatchActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, items));
|
|
524
543
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function consume(): Promise<void>;
|
|
2
|
+
export declare function publishFromAnywhere(): Promise<void>;
|
|
3
|
+
export declare function resumeFromCursor(topic: string): Promise<void>;
|
|
4
|
+
export declare function stopWithSignal(topic: string): Promise<void>;
|
|
5
|
+
export declare function namespaces(): Promise<void>;
|
|
6
|
+
export declare function resetTopic(): Promise<void>;
|
|
@@ -0,0 +1,192 @@
|
|
|
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 __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
+
var m = o[Symbol.asyncIterator], i;
|
|
14
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.consume = consume;
|
|
20
|
+
exports.publishFromAnywhere = publishFromAnywhere;
|
|
21
|
+
exports.resumeFromCursor = resumeFromCursor;
|
|
22
|
+
exports.stopWithSignal = stopWithSignal;
|
|
23
|
+
exports.namespaces = namespaces;
|
|
24
|
+
exports.resetTopic = resetTopic;
|
|
25
|
+
const crypto_1 = require("crypto");
|
|
26
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
27
|
+
const workflow_1 = require("./workflow");
|
|
28
|
+
const decode = (payload) => new TextDecoder().decode(payload);
|
|
29
|
+
function consume() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
var _a, e_1, _b, _c;
|
|
32
|
+
// > Consume
|
|
33
|
+
const topic = `progress-${(0, crypto_1.randomUUID)()}`;
|
|
34
|
+
yield workflow_1.progressTask.runNoWait({ topic });
|
|
35
|
+
try {
|
|
36
|
+
for (var _d = true, _e = __asyncValues(hatchet_client_1.hatchet.streams.events(topic)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
37
|
+
_c = _f.value;
|
|
38
|
+
_d = false;
|
|
39
|
+
const event = _c;
|
|
40
|
+
const { step, total } = JSON.parse(decode(event.payload));
|
|
41
|
+
console.log(`step ${step} of ${total}`);
|
|
42
|
+
// the stream outlives the run, so the reader decides when it's done
|
|
43
|
+
if (step === total) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
49
|
+
finally {
|
|
50
|
+
try {
|
|
51
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
52
|
+
}
|
|
53
|
+
finally { if (e_1) throw e_1.error; }
|
|
54
|
+
}
|
|
55
|
+
// !!
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function publishFromAnywhere() {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
// > Publish from anywhere
|
|
61
|
+
yield hatchet_client_1.hatchet.streams.publish('orders', JSON.stringify({ orderId: 'ord_123', status: 'shipped' }));
|
|
62
|
+
// !!
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function resumeFromCursor(topic) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
var _a, e_2, _b, _c, _d, e_3, _e, _f;
|
|
68
|
+
// > Resume from a cursor
|
|
69
|
+
let cursor;
|
|
70
|
+
try {
|
|
71
|
+
for (var _g = true, _h = __asyncValues(hatchet_client_1.hatchet.streams.events(topic)), _j; _j = yield _h.next(), _a = _j.done, !_a; _g = true) {
|
|
72
|
+
_c = _j.value;
|
|
73
|
+
_g = false;
|
|
74
|
+
const event = _c;
|
|
75
|
+
console.log(decode(event.payload));
|
|
76
|
+
({ cursor } = event);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
81
|
+
finally {
|
|
82
|
+
try {
|
|
83
|
+
if (!_g && !_a && (_b = _h.return)) yield _b.call(_h);
|
|
84
|
+
}
|
|
85
|
+
finally { if (e_2) throw e_2.error; }
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
// picks up right after the last event read, even from another process
|
|
89
|
+
for (var _k = true, _l = __asyncValues(hatchet_client_1.hatchet.streams.events(topic, { cursor })), _m; _m = yield _l.next(), _d = _m.done, !_d; _k = true) {
|
|
90
|
+
_f = _m.value;
|
|
91
|
+
_k = false;
|
|
92
|
+
const event = _f;
|
|
93
|
+
console.log(decode(event.payload));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
97
|
+
finally {
|
|
98
|
+
try {
|
|
99
|
+
if (!_k && !_d && (_e = _l.return)) yield _e.call(_l);
|
|
100
|
+
}
|
|
101
|
+
finally { if (e_3) throw e_3.error; }
|
|
102
|
+
}
|
|
103
|
+
// !!
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function stopWithSignal(topic) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
var _a, e_4, _b, _c;
|
|
109
|
+
// > Stop reading
|
|
110
|
+
const controller = new AbortController();
|
|
111
|
+
setTimeout(() => controller.abort(), 10000);
|
|
112
|
+
try {
|
|
113
|
+
for (var _d = true, _e = __asyncValues(hatchet_client_1.hatchet.streams.events(topic, { signal: controller.signal })), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
114
|
+
_c = _f.value;
|
|
115
|
+
_d = false;
|
|
116
|
+
const event = _c;
|
|
117
|
+
console.log(decode(event.payload));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
121
|
+
finally {
|
|
122
|
+
try {
|
|
123
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
124
|
+
}
|
|
125
|
+
finally { if (e_4) throw e_4.error; }
|
|
126
|
+
}
|
|
127
|
+
// !!
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function namespaces() {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
var _a, e_5, _b, _c;
|
|
133
|
+
// > Namespaces
|
|
134
|
+
yield hatchet_client_1.hatchet.streams.publish('updates', 'hello', { namespace: 'customer-a' });
|
|
135
|
+
try {
|
|
136
|
+
for (var _d = true, _e = __asyncValues(hatchet_client_1.hatchet.streams.events('updates', { namespace: 'customer-a' })), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
137
|
+
_c = _f.value;
|
|
138
|
+
_d = false;
|
|
139
|
+
const event = _c;
|
|
140
|
+
console.log(decode(event.payload));
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
145
|
+
finally {
|
|
146
|
+
try {
|
|
147
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
148
|
+
}
|
|
149
|
+
finally { if (e_5) throw e_5.error; }
|
|
150
|
+
}
|
|
151
|
+
// !!
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function resetTopic() {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
var _a, e_6, _b, _c;
|
|
157
|
+
// > Reset a topic
|
|
158
|
+
yield hatchet_client_1.hatchet.streams.reset('orders');
|
|
159
|
+
try {
|
|
160
|
+
// starts after the reset; readers that were already iterating aren't affected
|
|
161
|
+
for (var _d = true, _e = __asyncValues(hatchet_client_1.hatchet.streams.events('orders')), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
162
|
+
_c = _f.value;
|
|
163
|
+
_d = false;
|
|
164
|
+
const event = _c;
|
|
165
|
+
console.log(decode(event.payload));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
169
|
+
finally {
|
|
170
|
+
try {
|
|
171
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
172
|
+
}
|
|
173
|
+
finally { if (e_6) throw e_6.error; }
|
|
174
|
+
}
|
|
175
|
+
// !!
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function main() {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
yield consume();
|
|
181
|
+
yield publishFromAnywhere();
|
|
182
|
+
yield stopWithSignal('orders');
|
|
183
|
+
yield namespaces();
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (require.main === module) {
|
|
187
|
+
main()
|
|
188
|
+
.catch(console.error)
|
|
189
|
+
.finally(() => {
|
|
190
|
+
process.exit(0);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield hatchet_client_1.hatchet.worker('durable-streams-worker', {
|
|
17
|
+
workflows: [workflow_1.progressTask, workflow_1.retryingProgressTask],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ProgressInput = {
|
|
2
|
+
topic: string;
|
|
3
|
+
};
|
|
4
|
+
export declare const progressTask: import("../..").TaskWorkflowDeclaration<ProgressInput, {
|
|
5
|
+
steps: number;
|
|
6
|
+
}, {}, {}, {}, {}>;
|
|
7
|
+
export declare const retryingProgressTask: import("../..").TaskWorkflowDeclaration<ProgressInput, {
|
|
8
|
+
chunks: number;
|
|
9
|
+
}, {}, {}, {}, {}>;
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
exports.retryingProgressTask = exports.progressTask = void 0;
|
|
16
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
17
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
18
|
+
exports.progressTask = hatchet_client_1.hatchet.task({
|
|
19
|
+
name: 'durable-streams-progress',
|
|
20
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const total = 5;
|
|
22
|
+
for (let step = 1; step <= total; step += 1) {
|
|
23
|
+
yield (0, sleep_1.default)(500);
|
|
24
|
+
yield hatchet_client_1.hatchet.streams.publish(input.topic, JSON.stringify({ step, total }));
|
|
25
|
+
}
|
|
26
|
+
return { steps: total };
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
// !!
|
|
30
|
+
// > Reset on retry
|
|
31
|
+
exports.retryingProgressTask = hatchet_client_1.hatchet.task({
|
|
32
|
+
name: 'durable-streams-retrying-progress',
|
|
33
|
+
retries: 1,
|
|
34
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
// readers that subscribe from here on skip a failed attempt's messages
|
|
36
|
+
yield hatchet_client_1.hatchet.streams.reset(input.topic);
|
|
37
|
+
for (let chunk = 0; chunk < 3; chunk += 1) {
|
|
38
|
+
yield hatchet_client_1.hatchet.streams.publish(input.topic, JSON.stringify({ attempt: ctx.retryCount(), chunk }));
|
|
39
|
+
}
|
|
40
|
+
if (ctx.retryCount() === 0) {
|
|
41
|
+
throw new Error('intentional failure before the final message');
|
|
42
|
+
}
|
|
43
|
+
yield hatchet_client_1.hatchet.streams.publish(input.topic, JSON.stringify({ done: true }));
|
|
44
|
+
return { chunks: 3 };
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
// !!
|
|
@@ -33,23 +33,25 @@ const workflow_12 = require("./durable_event/workflow");
|
|
|
33
33
|
const workflow_13 = require("./durable_eviction/workflow");
|
|
34
34
|
const workflow_14 = require("./durable_callback_ordering/workflow");
|
|
35
35
|
const workflow_15 = require("./durable_sleep/workflow");
|
|
36
|
-
const workflow_16 = require("./
|
|
37
|
-
const workflow_17 = require("./
|
|
38
|
-
const workflow_18 = require("./
|
|
39
|
-
const workflow_19 = require("./
|
|
40
|
-
const workflow_20 = require("./
|
|
41
|
-
const workflow_21 = require("./
|
|
42
|
-
const workflow_22 = require("./
|
|
36
|
+
const workflow_16 = require("./durable-streams/workflow");
|
|
37
|
+
const workflow_17 = require("./logger/workflow");
|
|
38
|
+
const workflow_18 = require("./non_retryable/workflow");
|
|
39
|
+
const workflow_19 = require("./retry_after/workflow");
|
|
40
|
+
const workflow_20 = require("./on_failure/workflow");
|
|
41
|
+
const workflow_21 = require("./idempotency/workflow");
|
|
42
|
+
const workflow_22 = require("./on_event/workflow");
|
|
43
|
+
const workflow_23 = require("./return_exceptions/workflow");
|
|
44
|
+
const workflow_24 = require("./run_details/workflow");
|
|
43
45
|
const e2e_workflows_1 = require("./simple/e2e-workflows");
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
46
|
+
const workflow_25 = require("./batch_assign/workflow");
|
|
47
|
+
const workflow_26 = require("./streaming/workflow");
|
|
48
|
+
const workflow_27 = require("./subscribe_to_stream/workflow");
|
|
49
|
+
const workflow_28 = require("./timeout/workflow");
|
|
50
|
+
const workflow_29 = require("./webhooks/workflow");
|
|
51
|
+
const workflow_30 = require("./child_index/workflow");
|
|
52
|
+
const workflow_31 = require("./support_agent/workflow");
|
|
53
|
+
const workflow_32 = require("./welcome_email/workflow");
|
|
54
|
+
const workflow_33 = require("./pdf_pipeline/workflow");
|
|
53
55
|
const workflows = [
|
|
54
56
|
workflow_1.bulkChild,
|
|
55
57
|
workflow_1.bulkParentWorkflow,
|
|
@@ -90,6 +92,8 @@ const workflows = [
|
|
|
90
92
|
workflow_14.callbackOrderingMid,
|
|
91
93
|
workflow_14.callbackOrderingRoot,
|
|
92
94
|
workflow_15.durableSleep,
|
|
95
|
+
workflow_16.progressTask,
|
|
96
|
+
workflow_16.retryingProgressTask,
|
|
93
97
|
workflow_13.evictableSleep,
|
|
94
98
|
workflow_13.evictableWaitForEvent,
|
|
95
99
|
workflow_13.evictableMemoThenWaitForEvent,
|
|
@@ -99,45 +103,47 @@ const workflows = [
|
|
|
99
103
|
workflow_13.childTask,
|
|
100
104
|
workflow_13.bulkChildTask,
|
|
101
105
|
workflow_13.evictableChildBulkSpawn,
|
|
102
|
-
(0,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
workflow_19.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
workflow_21.
|
|
109
|
-
workflow_22.
|
|
106
|
+
(0, workflow_17.createLoggingWorkflow)(hatchet_client_1.hatchet),
|
|
107
|
+
workflow_18.nonRetryableWorkflow,
|
|
108
|
+
workflow_19.retryAfterUpstreamDelay,
|
|
109
|
+
workflow_19.retryAfterExponentialBackoff,
|
|
110
|
+
workflow_20.failureWorkflow,
|
|
111
|
+
workflow_21.idempotentTask,
|
|
112
|
+
workflow_21.idempotentTaskShortWindow,
|
|
113
|
+
workflow_22.lower,
|
|
114
|
+
workflow_23.returnExceptionsTask,
|
|
115
|
+
workflow_24.runDetailTestWorkflow,
|
|
110
116
|
e2e_workflows_1.helloWorld,
|
|
111
117
|
e2e_workflows_1.helloWorldDurable,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
118
|
+
workflow_26.streamingTask,
|
|
119
|
+
workflow_27.dagStream,
|
|
120
|
+
workflow_27.longStream,
|
|
121
|
+
workflow_28.timeoutTask,
|
|
122
|
+
workflow_28.refreshTimeoutTask,
|
|
123
|
+
workflow_29.webhookWorkflow,
|
|
124
|
+
workflow_30.childIndexChild,
|
|
125
|
+
workflow_30.childIndexParent,
|
|
126
|
+
workflow_30.scenarioTask,
|
|
127
|
+
workflow_30.orchestratorTask,
|
|
128
|
+
workflow_31.supportAgent,
|
|
129
|
+
workflow_31.triageTicket,
|
|
130
|
+
workflow_31.generateReply,
|
|
131
|
+
workflow_31.escalateTicket,
|
|
132
|
+
workflow_32.welcomeEmail,
|
|
133
|
+
workflow_33.pdfPipeline,
|
|
134
|
+
workflow_25.batchSimple,
|
|
135
|
+
workflow_25.batchKeyed,
|
|
136
|
+
workflow_25.batchKeyedFailable,
|
|
137
|
+
workflow_25.batchKeyedInterval,
|
|
138
|
+
workflow_25.batchLarge,
|
|
139
|
+
workflow_25.batchSingle,
|
|
140
|
+
workflow_25.batchOrdered,
|
|
141
|
+
workflow_25.batchBroadcast,
|
|
142
|
+
workflow_25.batchCancel,
|
|
143
|
+
workflow_25.child,
|
|
144
|
+
workflow_25.childBatch,
|
|
145
|
+
workflow_25.batchChildSpawn,
|
|
146
|
+
workflow_25.batchChildBatchSpawn,
|
|
141
147
|
];
|
|
142
148
|
function main() {
|
|
143
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const workflow_1 = require("./workflow");
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const res = yield workflow_1.retryAfterUpstreamDelay.run({ failingAttempts: 2 });
|
|
16
|
+
console.log(res);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (require.main === module) {
|
|
20
|
+
main();
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield hatchet_client_1.hatchet.worker('retry-after-worker', {
|
|
17
|
+
workflows: [workflow_1.retryAfterUpstreamDelay, workflow_1.retryAfterExponentialBackoff],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type UpstreamInput = {
|
|
2
|
+
failingAttempts: number;
|
|
3
|
+
};
|
|
4
|
+
export declare const retryAfterUpstreamDelay: import("../..").TaskWorkflowDeclaration<UpstreamInput, {
|
|
5
|
+
attempt: number;
|
|
6
|
+
}, {}, {}, {}, {}>;
|
|
7
|
+
export declare const retryAfterExponentialBackoff: import("../..").TaskWorkflowDeclaration<UpstreamInput, {
|
|
8
|
+
attempt: number;
|
|
9
|
+
}, {}, {}, {}, {}>;
|