@hatchet-dev/typescript-sdk 1.37.0 → 1.39.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 +62 -1
- package/clients/rest/generated/Api.js +50 -0
- package/clients/rest/generated/data-contracts.d.ts +146 -15
- package/clients/rest/generated/data-contracts.js +8 -1
- package/clients/streams/rpc.d.ts +8 -0
- package/clients/streams/rpc.js +14 -0
- package/clients/transport/fetch-transport.js +18 -1
- package/core/client.d.ts +2 -1
- package/core/client.js +3 -1
- package/core/features/streams.d.ts +68 -3
- package/core/features/streams.js +206 -5
- package/core/index.d.ts +9 -5
- package/core/index.js +13 -7
- package/core/types.d.ts +20 -0
- package/dist/check-core-esm-exports.mjs +19 -0
- package/package.json +2 -2
- package/protoc/v1/streams.d.ts +18 -0
- package/protoc/v1/streams.js +115 -1
- package/protoc-es/v1/streams_pb.d.ts +35 -0
- package/protoc-es/v1/streams_pb.js +12 -2
- package/scripts/check-core-esm-exports.mjs +19 -0
- package/v1/client/features/streams.d.ts +12 -18
- package/v1/client/features/streams.js +15 -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/durable_eviction/graceful-worker.d.ts +1 -0
- package/v1/examples/durable_eviction/graceful-worker.js +49 -0
- package/v1/examples/e2e-worker.js +59 -56
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Verifies that every export of the built core entry is visible to an ESM importer under Node:
|
|
3
|
+
// the entry is CommonJS, and Node derives its named exports statically, so a re-export written
|
|
4
|
+
// in a form that detection misses (a getter over a default import) vanishes for `import { X }`.
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
import { resolve } from 'node:path';
|
|
8
|
+
|
|
9
|
+
const entry = resolve('dist/core/index.js');
|
|
10
|
+
const cjs = createRequire(import.meta.url)(entry);
|
|
11
|
+
const esm = await import(pathToFileURL(entry).href);
|
|
12
|
+
const missing = Object.keys(cjs).filter((name) => name !== '__esModule' && !(name in esm));
|
|
13
|
+
|
|
14
|
+
if (missing.length > 0) {
|
|
15
|
+
console.error(`core entry exports hidden from ESM importers: ${missing.join(', ')}`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
console.log(`core entry: ${Object.keys(cjs).length} exports visible to ESM importers`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StreamCallOptions, StreamTopicMetadata } from '../../../core/types';
|
|
1
2
|
import { HatchetClient } from '../client';
|
|
2
3
|
export type StreamEvent = {
|
|
3
4
|
/** the message payload */
|
|
@@ -7,23 +8,7 @@ export type StreamEvent = {
|
|
|
7
8
|
/** when the message was stored */
|
|
8
9
|
createdAt?: Date;
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
export type StreamTopicMetadata = {
|
|
12
|
-
namespace: string;
|
|
13
|
-
topic: string;
|
|
14
|
-
tenantId: string;
|
|
15
|
-
messageCount: number;
|
|
16
|
-
/** resumes events() after the newest retained message; undefined when none is retained */
|
|
17
|
-
latestCursor?: string;
|
|
18
|
-
/** when the newest retained message was stored; undefined when none is retained */
|
|
19
|
-
lastPublishedAt?: Date;
|
|
20
|
-
};
|
|
21
|
-
export type StreamCallOptions = {
|
|
22
|
-
namespace?: string;
|
|
23
|
-
cursor?: string;
|
|
24
|
-
/** ends an events() iteration cleanly, without throwing */
|
|
25
|
-
signal?: AbortSignal;
|
|
26
|
-
};
|
|
11
|
+
export type { StreamCallOptions, StreamTopicMetadata } from '../../../core/types';
|
|
27
12
|
/**
|
|
28
13
|
* StreamsClient publishes to and reads from durable topics. Unlike
|
|
29
14
|
* `runs.subscribeToStream`, topics are stored, independent of any run, and
|
|
@@ -57,7 +42,16 @@ export declare class StreamsClient {
|
|
|
57
42
|
*/
|
|
58
43
|
topicMetadata(topic: string, options?: Pick<StreamCallOptions, 'namespace'>): Promise<StreamTopicMetadata>;
|
|
59
44
|
/**
|
|
60
|
-
*
|
|
45
|
+
* Makes events() calls without a cursor start after the topic's latest
|
|
46
|
+
* message. Readers already iterating, and any call with a cursor, are
|
|
47
|
+
* unaffected.
|
|
48
|
+
* @param topic - the topic to reset
|
|
49
|
+
* @param options - optional namespace override
|
|
50
|
+
*/
|
|
51
|
+
reset(topic: string, options?: Pick<StreamCallOptions, 'namespace'>): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Yields topic's messages after options.cursor, or from the oldest retained
|
|
54
|
+
* (or, once the topic is reset, after the reset).
|
|
61
55
|
* If the connection drops, it resubscribes from the last message yielded, so
|
|
62
56
|
* nothing is skipped or repeated. Ends when the server hangs up an idle
|
|
63
57
|
* 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
|
|
@@ -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
|
+
// !!
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DURABLE_WAIT_MARKED = "[e2e] durable wait marked";
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
exports.DURABLE_WAIT_MARKED = void 0;
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
const workflow_1 = require("./workflow");
|
|
15
|
+
exports.DURABLE_WAIT_MARKED = '[e2e] durable wait marked';
|
|
16
|
+
// Worker for the graceful termination e2e test. The test must not terminate
|
|
17
|
+
// this worker before the SDK has recorded the run as waiting, and nothing
|
|
18
|
+
// observable outside the process marks that moment: the engine writes the
|
|
19
|
+
// WAIT_FOR entry before it acks, and the SDK only calls markWaiting once the
|
|
20
|
+
// ack arrives. The eviction manager is created lazily on the worker's
|
|
21
|
+
// internal state, so it is wrapped on assignment to print a line the test can
|
|
22
|
+
// wait for.
|
|
23
|
+
function main() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const worker = yield hatchet_client_1.hatchet.worker('graceful-eviction-worker', {
|
|
26
|
+
workflows: [workflow_1.evictableSleepForGracefulTermination],
|
|
27
|
+
});
|
|
28
|
+
let manager;
|
|
29
|
+
Object.defineProperty(worker._internal, 'evictionManager', {
|
|
30
|
+
configurable: true,
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: () => manager,
|
|
33
|
+
set: (next) => {
|
|
34
|
+
manager = next;
|
|
35
|
+
if (!next)
|
|
36
|
+
return;
|
|
37
|
+
const markWaiting = next.markWaiting.bind(next);
|
|
38
|
+
next.markWaiting = (key, waitKind, resourceId) => {
|
|
39
|
+
markWaiting(key, waitKind, resourceId);
|
|
40
|
+
console.log(`${exports.DURABLE_WAIT_MARKED} key=${key} kind=${waitKind} resource=${resourceId}`);
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
yield worker.start();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (require.main === module) {
|
|
48
|
+
main();
|
|
49
|
+
}
|
|
@@ -33,24 +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("./
|
|
43
|
-
const workflow_23 = 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");
|
|
44
45
|
const e2e_workflows_1 = require("./simple/e2e-workflows");
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
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");
|
|
54
55
|
const workflows = [
|
|
55
56
|
workflow_1.bulkChild,
|
|
56
57
|
workflow_1.bulkParentWorkflow,
|
|
@@ -91,6 +92,8 @@ const workflows = [
|
|
|
91
92
|
workflow_14.callbackOrderingMid,
|
|
92
93
|
workflow_14.callbackOrderingRoot,
|
|
93
94
|
workflow_15.durableSleep,
|
|
95
|
+
workflow_16.progressTask,
|
|
96
|
+
workflow_16.retryingProgressTask,
|
|
94
97
|
workflow_13.evictableSleep,
|
|
95
98
|
workflow_13.evictableWaitForEvent,
|
|
96
99
|
workflow_13.evictableMemoThenWaitForEvent,
|
|
@@ -100,47 +103,47 @@ const workflows = [
|
|
|
100
103
|
workflow_13.childTask,
|
|
101
104
|
workflow_13.bulkChildTask,
|
|
102
105
|
workflow_13.evictableChildBulkSpawn,
|
|
103
|
-
(0,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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,
|
|
113
116
|
e2e_workflows_1.helloWorld,
|
|
114
117
|
e2e_workflows_1.helloWorldDurable,
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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,
|
|
144
147
|
];
|
|
145
148
|
function main() {
|
|
146
149
|
return __awaiter(this, void 0, void 0, function* () {
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.39.0";
|
package/version.js
CHANGED