async-lube 2.0.0 → 2.1.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/CHANGELOG.md +34 -0
- package/README.md +1 -1
- package/docs/http.md +1 -1
- package/docs/reference.md +4 -2
- package/docs/tasks.md +19 -2
- package/package.json +4 -5
- package/public.d.ts +112 -0
- package/src/attempt.js +17 -7
- package/src/durable/context.js +107 -64
- package/src/durable/error.js +39 -15
- package/src/durable/index.js +18 -10
- package/src/durable/journal.js +29 -14
- package/src/durable/json.js +26 -9
- package/src/durable/lease.js +15 -5
- package/src/durable/persist.js +60 -22
- package/src/durable/run.js +103 -41
- package/src/durable/send.js +30 -13
- package/src/durable/serve.js +30 -24
- package/src/durable/state.js +28 -13
- package/src/durable/store.js +19 -10
- package/src/durable/watch.js +31 -11
- package/src/errors.js +9 -3
- package/src/flow/attempts.js +49 -29
- package/src/flow/builder.js +260 -161
- package/src/flow/compile.js +86 -66
- package/src/flow/graph.js +108 -42
- package/src/flow/index.js +13 -7
- package/src/flow/items.js +79 -46
- package/src/flow/nodes.js +267 -117
- package/src/flow/refs.js +27 -13
- package/src/flow/resources.js +9 -3
- package/src/flow/run.js +287 -114
- package/src/flow/streams.js +44 -19
- package/src/flow/subflows.js +93 -53
- package/src/http/config.js +11 -5
- package/src/http/index.js +25 -14
- package/src/http/refresh.js +29 -12
- package/src/http/request.js +246 -151
- package/src/http/response.js +105 -50
- package/src/http/retry.js +52 -27
- package/src/http/socket.js +220 -172
- package/src/http/sse.js +113 -74
- package/src/http/throttle.js +9 -4
- package/src/http/url.js +58 -35
- package/src/http/xhr.js +29 -24
- package/src/index.js +1 -0
- package/src/key.js +3 -5
- package/src/limiter.js +146 -65
- package/src/offload.js +116 -85
- package/src/offload_module.js +594 -0
- package/src/options.js +8 -4
- package/src/redial.js +129 -0
- package/src/signal.js +14 -4
- package/src/stream.js +353 -198
- package/types/attempt.d.ts.map +1 -1
- package/types/durable/index.d.ts.map +1 -1
- package/types/durable/state.d.ts.map +1 -1
- package/types/durable/store.d.ts.map +1 -1
- package/types/errors.d.ts.map +1 -1
- package/types/http/index.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/limiter.d.ts +5 -1
- package/types/limiter.d.ts.map +1 -1
- package/types/offload.d.ts +2 -16
- package/types/offload.d.ts.map +1 -1
- package/types/redial.d.ts +28 -0
- package/types/redial.d.ts.map +1 -0
- package/types/stream.d.ts +2 -0
- package/types/stream.d.ts.map +1 -1
package/src/flow/attempts.js
CHANGED
|
@@ -43,7 +43,9 @@ export function make_context(
|
|
|
43
43
|
goto,
|
|
44
44
|
index: index ?? c.item_index,
|
|
45
45
|
get key() {
|
|
46
|
-
if (!run_state)
|
|
46
|
+
if (!run_state) {
|
|
47
|
+
return ""
|
|
48
|
+
}
|
|
47
49
|
return `${c.run_id}:${record.node.name}${index == null ? "" : "#" + index}:${run_state.serial}`
|
|
48
50
|
},
|
|
49
51
|
name: record.node.name,
|
|
@@ -52,7 +54,9 @@ export function make_context(
|
|
|
52
54
|
skip,
|
|
53
55
|
/** @param {number} ms */
|
|
54
56
|
sleep: ms => {
|
|
55
|
-
if (!run_state)
|
|
57
|
+
if (!run_state) {
|
|
58
|
+
return sleep_until(Date.now() + ms, signal)
|
|
59
|
+
}
|
|
56
60
|
const deadline = run_state.waits[run_state.wait++] ??= Date.now() + ms
|
|
57
61
|
return sleep_until(deadline, signal)
|
|
58
62
|
},
|
|
@@ -79,7 +83,9 @@ export async function run_attempts(c, record, token, parent, unit, run_once) {
|
|
|
79
83
|
} catch {
|
|
80
84
|
return { kind: "stale" }
|
|
81
85
|
}
|
|
82
|
-
if (token != record.token)
|
|
86
|
+
if (token != record.token) {
|
|
87
|
+
return { kind: "stale" }
|
|
88
|
+
}
|
|
83
89
|
run_state.delay = void 0
|
|
84
90
|
}
|
|
85
91
|
const index = unit ? Number(unit) : c.item_index
|
|
@@ -95,7 +101,9 @@ export async function run_attempts(c, record, token, parent, unit, run_once) {
|
|
|
95
101
|
* @returns {void}
|
|
96
102
|
*/
|
|
97
103
|
function end(type, error, again) {
|
|
98
|
-
if (!c.trace)
|
|
104
|
+
if (!c.trace) {
|
|
105
|
+
return
|
|
106
|
+
}
|
|
99
107
|
const time = Date.now()
|
|
100
108
|
const base = {
|
|
101
109
|
attempt,
|
|
@@ -109,16 +117,18 @@ export async function run_attempts(c, record, token, parent, unit, run_once) {
|
|
|
109
117
|
type == "fail" ? { ...base, error, retry: !!again, type } : { ...base, type }
|
|
110
118
|
)
|
|
111
119
|
}
|
|
112
|
-
if (c.trace)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
if (c.trace) {
|
|
121
|
+
emit(
|
|
122
|
+
c,
|
|
123
|
+
{
|
|
124
|
+
attempt,
|
|
125
|
+
index,
|
|
126
|
+
node: record.node.name,
|
|
127
|
+
time: started,
|
|
128
|
+
type: "start"
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
}
|
|
122
132
|
const controller = timeout ? new AbortController() : void 0
|
|
123
133
|
const signal = controller ? controller.signal : parent
|
|
124
134
|
const unlink = controller ? link_signal(controller, parent) : noop
|
|
@@ -133,7 +143,9 @@ export async function run_attempts(c, record, token, parent, unit, run_once) {
|
|
|
133
143
|
const pending = Promise.resolve()
|
|
134
144
|
.then(
|
|
135
145
|
() => {
|
|
136
|
-
if (signal.aborted)
|
|
146
|
+
if (signal.aborted) {
|
|
147
|
+
throw signal.reason
|
|
148
|
+
}
|
|
137
149
|
return run_once(signal, run_state, first)
|
|
138
150
|
}
|
|
139
151
|
)
|
|
@@ -203,7 +215,9 @@ export async function run_attempts(c, record, token, parent, unit, run_once) {
|
|
|
203
215
|
} finally {
|
|
204
216
|
record.delaying--
|
|
205
217
|
}
|
|
206
|
-
if (token != record.token)
|
|
218
|
+
if (token != record.token) {
|
|
219
|
+
return { kind: "stale" }
|
|
220
|
+
}
|
|
207
221
|
run_state.delay = void 0
|
|
208
222
|
}
|
|
209
223
|
} finally {
|
|
@@ -229,7 +243,7 @@ export function run_single(c, record, token) {
|
|
|
229
243
|
/** @type {AbortController} */(record.controller)/**/.signal,
|
|
230
244
|
"",
|
|
231
245
|
(signal, run_state, first) => {
|
|
232
|
-
const values = args_of(
|
|
246
|
+
const values = args_of(record)
|
|
233
247
|
const gate = record.gate
|
|
234
248
|
if (gate) {
|
|
235
249
|
if (gate !== true) {
|
|
@@ -242,17 +256,19 @@ export function run_single(c, record, token) {
|
|
|
242
256
|
}
|
|
243
257
|
record.gate = void 0
|
|
244
258
|
}
|
|
245
|
-
if (!node.sub)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
259
|
+
if (!node.sub) {
|
|
260
|
+
return /** @type {Task} */(node.run)/**/(
|
|
261
|
+
...values,
|
|
262
|
+
make_context(
|
|
263
|
+
c,
|
|
264
|
+
record,
|
|
265
|
+
signal,
|
|
266
|
+
run_state.attempt,
|
|
267
|
+
void 0,
|
|
268
|
+
run_state
|
|
269
|
+
)
|
|
254
270
|
)
|
|
255
|
-
|
|
271
|
+
}
|
|
256
272
|
const sub_state = values.length > 1
|
|
257
273
|
? values
|
|
258
274
|
: values.length
|
|
@@ -277,9 +293,13 @@ export function run_single(c, record, token) {
|
|
|
277
293
|
*/
|
|
278
294
|
function take_run(record, unit) {
|
|
279
295
|
const current = record.runs.get(unit)
|
|
280
|
-
if (current)
|
|
296
|
+
if (current) {
|
|
297
|
+
return current
|
|
298
|
+
}
|
|
281
299
|
const saved = record.resume_runs?.[unit]
|
|
282
|
-
if (saved && record.resume_runs)
|
|
300
|
+
if (saved && record.resume_runs) {
|
|
301
|
+
delete record.resume_runs[unit]
|
|
302
|
+
}
|
|
283
303
|
/** @type {RunState} */
|
|
284
304
|
const run_state = {
|
|
285
305
|
attempt: saved?.attempt ?? 1,
|