@decaf-ts/core 0.26.1 → 0.26.3
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/README.md +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/lib/cjs/index.cjs +3 -3
- package/lib/cjs/tasks/TaskContext.cjs +9 -2
- package/lib/cjs/tasks/TaskContext.cjs.map +1 -1
- package/lib/cjs/tasks/TaskEngine.cjs +76 -30
- package/lib/cjs/tasks/TaskEngine.cjs.map +1 -1
- package/lib/cjs/tasks/builder.cjs +8 -0
- package/lib/cjs/tasks/builder.cjs.map +1 -1
- package/lib/cjs/tasks/logging.cjs +12 -3
- package/lib/cjs/tasks/logging.cjs.map +1 -1
- package/lib/cjs/tasks/models/TaskStepResultModel.cjs +6 -0
- package/lib/cjs/tasks/models/TaskStepResultModel.cjs.map +1 -1
- package/lib/cjs/tasks/models/TaskStepSpecModel.cjs +14 -0
- package/lib/cjs/tasks/models/TaskStepSpecModel.cjs.map +1 -1
- package/lib/cjs/utils/throttling.cjs +103 -78
- package/lib/cjs/utils/throttling.cjs.map +1 -1
- package/lib/esm/index.js +3 -3
- package/lib/esm/tasks/TaskContext.js +9 -2
- package/lib/esm/tasks/TaskContext.js.map +1 -1
- package/lib/esm/tasks/TaskEngine.js +76 -30
- package/lib/esm/tasks/TaskEngine.js.map +1 -1
- package/lib/esm/tasks/builder.js +8 -0
- package/lib/esm/tasks/builder.js.map +1 -1
- package/lib/esm/tasks/logging.js +12 -3
- package/lib/esm/tasks/logging.js.map +1 -1
- package/lib/esm/tasks/models/TaskStepResultModel.js +7 -1
- package/lib/esm/tasks/models/TaskStepResultModel.js.map +1 -1
- package/lib/esm/tasks/models/TaskStepSpecModel.js +15 -1
- package/lib/esm/tasks/models/TaskStepSpecModel.js.map +1 -1
- package/lib/esm/utils/throttling.js +101 -78
- package/lib/esm/utils/throttling.js.map +1 -1
- package/lib/types/index.d.cts +3 -3
- package/lib/types/index.d.mts +3 -3
- package/lib/types/tasks/TaskContext.d.cts +2 -1
- package/lib/types/tasks/TaskContext.d.mts +2 -1
- package/lib/types/tasks/builder.d.cts +2 -0
- package/lib/types/tasks/builder.d.mts +2 -0
- package/lib/types/tasks/models/TaskStepResultModel.d.cts +1 -0
- package/lib/types/tasks/models/TaskStepResultModel.d.mts +1 -0
- package/lib/types/tasks/models/TaskStepSpecModel.d.cts +3 -0
- package/lib/types/tasks/models/TaskStepSpecModel.d.mts +3 -0
- package/lib/types/tasks/types.d.cts +2 -1
- package/lib/types/tasks/types.d.mts +2 -1
- package/lib/types/utils/throttling.d.cts +13 -8
- package/lib/types/utils/throttling.d.mts +13 -8
- package/package.json +1 -1
|
@@ -1,57 +1,107 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThrottleMode = void 0;
|
|
4
|
+
exports.splitByCount = splitByCount;
|
|
5
|
+
exports.splitBySize = splitBySize;
|
|
3
6
|
exports.throttle = throttle;
|
|
4
7
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
5
8
|
const index_js_1 = require("./../persistence/index.cjs");
|
|
6
9
|
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
7
|
-
function
|
|
8
|
-
|
|
10
|
+
(function (ThrottleMode) {
|
|
11
|
+
ThrottleMode["BY_COUNT"] = "count";
|
|
12
|
+
ThrottleMode["BY_SIZE"] = "size";
|
|
13
|
+
})(exports.ThrottleMode || (exports.ThrottleMode = {}));
|
|
14
|
+
function splitByCount(count) {
|
|
15
|
+
if (count <= 0)
|
|
16
|
+
throw new db_decorators_1.InternalError("splitByCount: count must be greater than zero");
|
|
17
|
+
return (items) => {
|
|
18
|
+
const chunks = [];
|
|
19
|
+
for (let i = 0; i < items.length; i += count)
|
|
20
|
+
chunks.push(items.slice(i, i + count));
|
|
21
|
+
return chunks;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function splitBySize(maxBytes) {
|
|
25
|
+
if (maxBytes <= 0)
|
|
26
|
+
throw new db_decorators_1.InternalError("splitBySize: maxBytes must be greater than zero");
|
|
27
|
+
return (items) => {
|
|
28
|
+
const chunks = [];
|
|
29
|
+
let current = [];
|
|
30
|
+
let size = 0;
|
|
31
|
+
for (const item of items) {
|
|
32
|
+
const itemSize = safeByteLength(item);
|
|
33
|
+
if (current.length > 0 && size + itemSize > maxBytes) {
|
|
34
|
+
chunks.push(current);
|
|
35
|
+
current = [item];
|
|
36
|
+
size = itemSize;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
current.push(item);
|
|
40
|
+
size += itemSize;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (current.length > 0)
|
|
44
|
+
chunks.push(current);
|
|
45
|
+
return chunks;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function throttle(value, modeOrOptions, maybeOptions) {
|
|
49
|
+
let splitter;
|
|
50
|
+
let options;
|
|
51
|
+
if (typeof value === "function") {
|
|
52
|
+
splitter = value;
|
|
53
|
+
options = modeOrOptions ?? {};
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const mode = typeof modeOrOptions === "string"
|
|
57
|
+
? modeOrOptions
|
|
58
|
+
: exports.ThrottleMode.BY_COUNT;
|
|
59
|
+
options =
|
|
60
|
+
(typeof modeOrOptions === "object" && !Array.isArray(modeOrOptions)
|
|
61
|
+
? modeOrOptions
|
|
62
|
+
: maybeOptions) ?? {};
|
|
63
|
+
splitter =
|
|
64
|
+
mode === exports.ThrottleMode.BY_SIZE ? splitBySize(value) : splitByCount(value);
|
|
65
|
+
}
|
|
66
|
+
const { delayMs, argIndex = 0 } = options;
|
|
67
|
+
return function throttleDecorator(target, propertyKey, descriptor) {
|
|
9
68
|
function throttleDec(target, propertyKey, descriptor) {
|
|
10
69
|
descriptor.value = new Proxy(descriptor.value, {
|
|
11
|
-
async apply(
|
|
70
|
+
async apply(originalFn, thisArg, args) {
|
|
12
71
|
const invocationArgs = args;
|
|
13
|
-
const
|
|
14
|
-
try {
|
|
15
|
-
return typeof cfg === "function"
|
|
16
|
-
? cfg(...invocationArgs)
|
|
17
|
-
: cfg;
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
throw new db_decorators_1.InternalError(`Failed to obtain throttling configuration from handler: ${e}`);
|
|
21
|
-
}
|
|
22
|
-
})();
|
|
23
|
-
const { log, ctx } = (await thisArg["logCtx"](args, index_js_1.PersistenceKeys.THROTTLE, true)).for(throttle);
|
|
72
|
+
const { log, ctx } = (await thisArg["logCtx"](args, originalFn.name, true)).for(throttle);
|
|
24
73
|
const normalizedIndices = normalizeArgIndex(argIndex);
|
|
25
|
-
if (!normalizedIndices.length)
|
|
26
|
-
throw new db_decorators_1.InternalError("@
|
|
27
|
-
}
|
|
74
|
+
if (!normalizedIndices.length)
|
|
75
|
+
throw new db_decorators_1.InternalError("@throttle() expects at least one argument index to throttle");
|
|
28
76
|
normalizedIndices.forEach((index) => {
|
|
29
77
|
if (index >= invocationArgs.length)
|
|
30
|
-
throw new db_decorators_1.InternalError(`@
|
|
78
|
+
throw new db_decorators_1.InternalError(`@throttle() requires argument index ${index} but only ${invocationArgs.length} provided`);
|
|
31
79
|
if (!Array.isArray(invocationArgs[index]))
|
|
32
|
-
throw new db_decorators_1.InternalError(`@
|
|
80
|
+
throw new db_decorators_1.InternalError(`@throttle() expects argument at index ${index} to be an array`);
|
|
33
81
|
});
|
|
34
82
|
const arrays = normalizedIndices.map((idx) => invocationArgs[idx]);
|
|
35
83
|
const total = arrays[0].length;
|
|
36
|
-
if (!arrays.every((arr) => arr.length === total))
|
|
37
|
-
throw new db_decorators_1.InternalError("@
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
84
|
+
if (!arrays.every((arr) => arr.length === total))
|
|
85
|
+
throw new db_decorators_1.InternalError("@throttle() requires all targeted arguments to have the same length");
|
|
86
|
+
if (total === 0)
|
|
87
|
+
return originalFn.apply(thisArg, invocationArgs);
|
|
88
|
+
const primaryChunks = splitter(arrays[0]);
|
|
89
|
+
const chunkArgsList = buildChunkArgsList(primaryChunks, arrays, normalizedIndices, invocationArgs);
|
|
90
|
+
const breakOnSingleFailure = options.breakOnSingleFailure ??
|
|
91
|
+
(() => {
|
|
92
|
+
try {
|
|
93
|
+
return ctx.get("breakOnSingleFailureInBulk");
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
})() ??
|
|
99
|
+
true;
|
|
50
100
|
const collectedResults = [];
|
|
51
101
|
const errors = [];
|
|
52
102
|
for (const chunkArgs of chunkArgsList) {
|
|
53
103
|
try {
|
|
54
|
-
const chunkResult = await
|
|
104
|
+
const chunkResult = await originalFn.apply(thisArg, chunkArgs);
|
|
55
105
|
mergeResult(chunkResult, collectedResults);
|
|
56
106
|
}
|
|
57
107
|
catch (error) {
|
|
@@ -59,9 +109,8 @@ function throttle(cfg = { count: 1 }, argIndex = 0) {
|
|
|
59
109
|
throw error;
|
|
60
110
|
errors.push(error);
|
|
61
111
|
}
|
|
62
|
-
if (
|
|
63
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
64
|
-
}
|
|
112
|
+
if (delayMs)
|
|
113
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
65
114
|
}
|
|
66
115
|
if (errors.length) {
|
|
67
116
|
log.warn(`${String(propertyKey)} throttled execution continued with ${errors.length} failure(s)`);
|
|
@@ -73,56 +122,32 @@ function throttle(cfg = { count: 1 }, argIndex = 0) {
|
|
|
73
122
|
},
|
|
74
123
|
});
|
|
75
124
|
}
|
|
76
|
-
return (0, decoration_1.apply)((0, decoration_1.methodMetadata)(decoration_1.Metadata.key(index_js_1.PersistenceKeys.THROTTLE, propertyKey),
|
|
125
|
+
return (0, decoration_1.apply)((0, decoration_1.methodMetadata)(decoration_1.Metadata.key(index_js_1.PersistenceKeys.THROTTLE, propertyKey), options), throttleDec)(target, propertyKey, descriptor);
|
|
77
126
|
};
|
|
78
127
|
}
|
|
79
128
|
function normalizeArgIndex(argIndex) {
|
|
80
129
|
const entries = (Array.isArray(argIndex) ? argIndex : [argIndex]).map((idx) => {
|
|
81
130
|
if (!Number.isFinite(idx) || idx < 0)
|
|
82
|
-
throw new db_decorators_1.InternalError("@
|
|
131
|
+
throw new db_decorators_1.InternalError("@throttle() argument indexes must be non-negative integers");
|
|
83
132
|
return idx;
|
|
84
133
|
});
|
|
85
134
|
return Array.from(new Set(entries)).sort((a, b) => a - b);
|
|
86
135
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
throw new db_decorators_1.InternalError("@throttling() configuration 'bufferSize' must be greater than zero");
|
|
103
|
-
const spans = [];
|
|
104
|
-
let start = 0;
|
|
105
|
-
let size = 0;
|
|
106
|
-
for (let idx = 0; idx < total; idx++) {
|
|
107
|
-
const entrySize = estimateEntrySize(arrays, idx);
|
|
108
|
-
if (size > 0 && size + entrySize > cfg.bufferSize) {
|
|
109
|
-
spans.push({ start, end: idx });
|
|
110
|
-
start = idx;
|
|
111
|
-
size = entrySize;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
size += entrySize;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (start < total || !spans.length) {
|
|
118
|
-
spans.push({ start, end: total });
|
|
119
|
-
}
|
|
120
|
-
return spans;
|
|
121
|
-
}
|
|
122
|
-
return [{ start: 0, end: total }];
|
|
123
|
-
}
|
|
124
|
-
function estimateEntrySize(arrays, index) {
|
|
125
|
-
return arrays.reduce((acc, array) => acc + safeByteLength(array[index]), 0);
|
|
136
|
+
function buildChunkArgsList(primaryChunks, arrays, normalizedIndices, invocationArgs) {
|
|
137
|
+
let offset = 0;
|
|
138
|
+
return primaryChunks.map((chunk) => {
|
|
139
|
+
const chunkLen = chunk.length;
|
|
140
|
+
const args = invocationArgs.map((arg, idx) => {
|
|
141
|
+
const targetIdx = normalizedIndices.indexOf(idx);
|
|
142
|
+
if (targetIdx === -1)
|
|
143
|
+
return arg;
|
|
144
|
+
return targetIdx === 0
|
|
145
|
+
? chunk
|
|
146
|
+
: arrays[targetIdx].slice(offset, offset + chunkLen);
|
|
147
|
+
});
|
|
148
|
+
offset += chunkLen;
|
|
149
|
+
return args;
|
|
150
|
+
});
|
|
126
151
|
}
|
|
127
152
|
function safeByteLength(value) {
|
|
128
153
|
if (value === null || typeof value === "undefined")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttling.js","sourceRoot":"","sources":["throttling.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"throttling.js","sourceRoot":"","sources":["throttling.js"],"names":[],"mappings":";;;AAQA,oCASC;AACD,kCAuBC;AACD,4BA+EC;AAzHD,qDAAuE;AACvE,wDAA4D;AAC5D,2DAAwD;AAExD,CAAC,UAAU,YAAY;IACnB,YAAY,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC;IACnC,YAAY,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;AACrC,CAAC,CAAC,CAAC,oBAAY,IAAI,CAAC,oBAAY,GAAG,EAAE,CAAC,CAAC,CAAC;AACxC,SAAgB,YAAY,CAAC,KAAK;IAC9B,IAAI,KAAK,IAAI,CAAC;QACV,MAAM,IAAI,6BAAa,CAAC,+CAA+C,CAAC,CAAC;IAC7E,OAAO,CAAC,KAAK,EAAE,EAAE;QACb,MAAM,MAAM,GAAG,EAAE,CAAC;QAClB,KAAK,IAAI,CAAC,GAAG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AAI,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC;AACD,SAAS,cAAc,CAAC,KAAK;IACzB,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,WAAW;QAC9C,OAAO,CAAC,CAAC;IACb,IAAI,CAAC;QACD,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACpD,CAAC;IACD,MAAM,CAAC;QACH,OAAO,CAAC,CAAC;IACb,CAAC;AACL,CAAC;AACD,SAAS,WAAW,CAAC,MAAM,EAAE,SAAS;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACxB,SAAS,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;IAC9B,CAAC;SACI,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QACrC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;AACL,CAAC;AACD,sCAAsC"}
|
package/lib/esm/index.js
CHANGED
|
@@ -33,21 +33,21 @@ export * from "./persistence/index.js";
|
|
|
33
33
|
* @const VERSION
|
|
34
34
|
* @memberOf module:core
|
|
35
35
|
*/
|
|
36
|
-
export const VERSION = "0.26.
|
|
36
|
+
export const VERSION = "0.26.2";
|
|
37
37
|
/**
|
|
38
38
|
* @description Represents the current commit hash of the module build.
|
|
39
39
|
* @summary Stores the current git commit hash for the package. The build replaces
|
|
40
40
|
* the placeholder with the actual commit hash at publish time.
|
|
41
41
|
* @const COMMIT
|
|
42
42
|
*/
|
|
43
|
-
export const COMMIT = "
|
|
43
|
+
export const COMMIT = "3e8a41d";
|
|
44
44
|
/**
|
|
45
45
|
* @description Represents the full version string of the module.
|
|
46
46
|
* @summary Stores the semver version and commit hash for the package.
|
|
47
47
|
* The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
|
|
48
48
|
* @const FULL_VERSION
|
|
49
49
|
*/
|
|
50
|
-
export const FULL_VERSION = "0.26.
|
|
50
|
+
export const FULL_VERSION = "0.26.2-3e8a41d";
|
|
51
51
|
/**
|
|
52
52
|
* @description Stores the current package version
|
|
53
53
|
* @summary A constant representing the version of the core package
|
|
@@ -81,12 +81,19 @@ export class TaskContext extends Context {
|
|
|
81
81
|
scheduleSteps(...steps) {
|
|
82
82
|
const normalized = (steps ?? []).map((step) => step instanceof TaskStepSpecModel ? step : new TaskStepSpecModel(step));
|
|
83
83
|
return {
|
|
84
|
-
afterCurrent: async () => {
|
|
84
|
+
afterCurrent: async (ctx) => {
|
|
85
85
|
const scheduler = this.getOrUndefined("scheduleCompositeSteps");
|
|
86
86
|
if (!scheduler) {
|
|
87
87
|
throw new InternalError("scheduleSteps().afterCurrent() is only available while running a composite task step");
|
|
88
88
|
}
|
|
89
|
-
await scheduler(normalized);
|
|
89
|
+
await scheduler(normalized, ctx);
|
|
90
|
+
},
|
|
91
|
+
atEnd: async (ctx) => {
|
|
92
|
+
const scheduler = this.getOrUndefined("scheduleCompositeStepsAtEnd");
|
|
93
|
+
if (!scheduler) {
|
|
94
|
+
throw new InternalError("scheduleSteps().atEnd() is only available while running a composite task step");
|
|
95
|
+
}
|
|
96
|
+
await scheduler(normalized, ctx);
|
|
90
97
|
},
|
|
91
98
|
};
|
|
92
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskContext.js","sourceRoot":"","sources":["../../../src/tasks/TaskContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oCAA+B;AAIjD,OAAO,EAAE,cAAc,EAAE,mCAAgC;AACzD,OAAO,EAAE,UAAU,EAAE,uBAAoB;AACzC,OAAO,EAAE,cAAc,EAAE,mBAAgB;AACzC,OAAO,EAAE,oBAAoB,EAA0B,kCAA+B;AACtF,OAAO,EAAE,iBAAiB,EAAE,sCAAmC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAM,OAAO,WAAY,SAA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A+E,CAChF,CAAC;gBACJ,CAAC;gBACD,MAAM,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;YACnC,CAAC;SACF,CAAC;IACJ,CAAC;IAED,YAAY,GAAkB;QAC5B,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;CACF"}
|
|
@@ -708,7 +708,8 @@ export class TaskEngine extends AbsContextual {
|
|
|
708
708
|
totalSteps: steps.length,
|
|
709
709
|
});
|
|
710
710
|
const stepIndex = idx;
|
|
711
|
-
context.cache.put("scheduleCompositeSteps", async (newSteps) => {
|
|
711
|
+
context.cache.put("scheduleCompositeSteps", async (newSteps, ctx) => {
|
|
712
|
+
const log = ctx.logger.for("scheduleSteps.afterCurrent");
|
|
712
713
|
const normalizedNewSteps = this.normalizeSteps(newSteps);
|
|
713
714
|
if (!normalizedNewSteps.length)
|
|
714
715
|
return;
|
|
@@ -719,6 +720,31 @@ export class TaskEngine extends AbsContextual {
|
|
|
719
720
|
const persisted = await this.tasks.update(task, context);
|
|
720
721
|
Object.assign(task, persisted);
|
|
721
722
|
steps = this.normalizeSteps(task.steps);
|
|
723
|
+
log.verbose(`Inserted ${normalizedNewSteps.length} steps at index ${insertionIndex}`);
|
|
724
|
+
const updateEvent = await this.persistEvent(context, task.id, TaskEventType.UPDATE, {
|
|
725
|
+
status: "update",
|
|
726
|
+
currentStep: stepIndex,
|
|
727
|
+
totalSteps: steps.length,
|
|
728
|
+
output: {
|
|
729
|
+
added: normalizedNewSteps.length,
|
|
730
|
+
insertionIndex,
|
|
731
|
+
},
|
|
732
|
+
});
|
|
733
|
+
this.bus.emit(updateEvent, context);
|
|
734
|
+
});
|
|
735
|
+
context.cache.put("scheduleCompositeStepsAtEnd", async (newSteps, ctx) => {
|
|
736
|
+
const log = ctx.logger.for("scheduleSteps.atEnd");
|
|
737
|
+
const normalizedNewSteps = this.normalizeSteps(newSteps);
|
|
738
|
+
if (!normalizedNewSteps.length)
|
|
739
|
+
return;
|
|
740
|
+
const currentSteps = this.normalizeSteps(task.steps);
|
|
741
|
+
const insertionIndex = currentSteps.length;
|
|
742
|
+
currentSteps.push(...normalizedNewSteps);
|
|
743
|
+
task.steps = currentSteps;
|
|
744
|
+
const persisted = await this.tasks.update(task, context);
|
|
745
|
+
Object.assign(task, persisted);
|
|
746
|
+
steps = this.normalizeSteps(task.steps);
|
|
747
|
+
log.verbose(`Appended ${normalizedNewSteps.length} steps at tail (index ${insertionIndex})`);
|
|
722
748
|
const updateEvent = await this.persistEvent(context, task.id, TaskEventType.UPDATE, {
|
|
723
749
|
status: "update",
|
|
724
750
|
currentStep: stepIndex,
|
|
@@ -734,34 +760,53 @@ export class TaskEngine extends AbsContextual {
|
|
|
734
760
|
LogLevel.info,
|
|
735
761
|
`Composite step ${idx + 1}/${steps.length}: ${step.classification}`,
|
|
736
762
|
]);
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
763
|
+
const stepMaxAttempts = step.maxAttempts ?? 1;
|
|
764
|
+
let stepAttempt = 0;
|
|
765
|
+
let lastStepErr;
|
|
766
|
+
while (stepAttempt < stepMaxAttempts) {
|
|
767
|
+
try {
|
|
768
|
+
const out = await handler.run(step.input, context);
|
|
769
|
+
// Ensure step-tagged logs are flushed before advancing the step pointer.
|
|
770
|
+
await context.flush();
|
|
771
|
+
const now = new Date();
|
|
772
|
+
results[stepIndex] = new TaskStepResultModel({
|
|
773
|
+
status: TaskStatus.SUCCEEDED,
|
|
774
|
+
output: out,
|
|
775
|
+
attempt: stepAttempt + 1,
|
|
776
|
+
createdAt: now,
|
|
777
|
+
updatedAt: now,
|
|
778
|
+
});
|
|
779
|
+
const cacheKey = `${task.id}:step:${stepIndex}`;
|
|
780
|
+
cacheResult(step.classification, out);
|
|
781
|
+
cacheResult(cacheKey, out);
|
|
782
|
+
idx = stepIndex + 1;
|
|
783
|
+
task.stepResults = results;
|
|
784
|
+
task.currentStep = idx;
|
|
785
|
+
const persisted = await this.tasks.update(task);
|
|
786
|
+
Object.assign(task, persisted);
|
|
787
|
+
await this.emitProgress(context, task.id, {
|
|
788
|
+
currentStep: idx,
|
|
789
|
+
totalSteps: steps.length,
|
|
790
|
+
output: out,
|
|
791
|
+
});
|
|
792
|
+
lastStepErr = undefined;
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
catch (err) {
|
|
796
|
+
stepAttempt++;
|
|
797
|
+
lastStepErr = err;
|
|
798
|
+
if (stepAttempt < stepMaxAttempts) {
|
|
799
|
+
const stepBackoff = this.normalizeBackoff(step.backoff ?? task.backoff);
|
|
800
|
+
const delay = computeBackoffMs(stepAttempt, stepBackoff);
|
|
801
|
+
await context.pipe(LogLevel.warn, `Composite step ${idx} attempt ${stepAttempt}/${stepMaxAttempts} failed, retrying in ${delay}ms`, { classification: step.classification, attempt: stepAttempt, delay });
|
|
802
|
+
await sleep(delay);
|
|
803
|
+
await context.heartbeat();
|
|
804
|
+
}
|
|
805
|
+
}
|
|
761
806
|
}
|
|
762
|
-
|
|
807
|
+
if (lastStepErr) {
|
|
763
808
|
try {
|
|
764
|
-
await handler.catch?.(step.input,
|
|
809
|
+
await handler.catch?.(step.input, lastStepErr, context);
|
|
765
810
|
}
|
|
766
811
|
catch (catchErr) {
|
|
767
812
|
ctx.logger.warn("composite step catch() hook failed", {
|
|
@@ -771,17 +816,18 @@ export class TaskEngine extends AbsContextual {
|
|
|
771
816
|
const now = new Date();
|
|
772
817
|
results[idx] = new TaskStepResultModel({
|
|
773
818
|
status: TaskStatus.FAILED,
|
|
774
|
-
error: serializeError(
|
|
819
|
+
error: serializeError(lastStepErr),
|
|
820
|
+
attempt: stepAttempt,
|
|
775
821
|
createdAt: now,
|
|
776
822
|
updatedAt: now,
|
|
777
823
|
});
|
|
778
824
|
task.stepResults = results;
|
|
779
825
|
task.currentStep = idx;
|
|
780
|
-
task.error = serializeError(
|
|
826
|
+
task.error = serializeError(lastStepErr);
|
|
781
827
|
// persist failure context before throwing (retry logic happens outside)
|
|
782
828
|
const persisted = await this.tasks.update(task);
|
|
783
829
|
Object.assign(task, persisted);
|
|
784
|
-
throw
|
|
830
|
+
throw lastStepErr;
|
|
785
831
|
}
|
|
786
832
|
}
|
|
787
833
|
return { stepResults: results };
|