@brandboostinggmbh/observable-workflows 0.4.2 → 0.4.4
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/dist/index.js +31 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23,6 +23,25 @@ function insertStepRecordFull(context, { instanceId, name, status, metadata, sta
|
|
|
23
23
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
24
24
|
).bind(instanceId, name, status, metadata, startTime, endTime, result, error, context.tenantId).run();
|
|
25
25
|
}
|
|
26
|
+
async function getStepRecord(context, stepName, instanceId) {
|
|
27
|
+
const existingStep = await context.D1.prepare(
|
|
28
|
+
/* sql */
|
|
29
|
+
`SELECT * FROM StepTable WHERE instanceId = ? AND stepName = ? AND tenantId = ?`
|
|
30
|
+
).bind(instanceId, stepName, context.tenantId).first();
|
|
31
|
+
const row = existingStep;
|
|
32
|
+
if (row) return {
|
|
33
|
+
instanceId: row.instanceId,
|
|
34
|
+
name: row.stepName,
|
|
35
|
+
status: row.stepStatus,
|
|
36
|
+
metadata: tryDeserializeObj(row.stepMetadata, context.serializer),
|
|
37
|
+
startTime: row.startTime,
|
|
38
|
+
endTime: row.endTime,
|
|
39
|
+
result: tryDeserializeObj(row.result, context.serializer),
|
|
40
|
+
error: tryDeserializeObj(row.error, context.serializer),
|
|
41
|
+
tenantId: row.tenantId
|
|
42
|
+
};
|
|
43
|
+
else return null;
|
|
44
|
+
}
|
|
26
45
|
function pushLogToDB(options, { instanceId, stepName, message, timestamp, type, logOrder, tenantId }) {
|
|
27
46
|
return options.D1.prepare(
|
|
28
47
|
/* sql */
|
|
@@ -31,6 +50,14 @@ function pushLogToDB(options, { instanceId, stepName, message, timestamp, type,
|
|
|
31
50
|
VALUES (?, ?, ?, ?, ?, ?, ?)`
|
|
32
51
|
).bind(instanceId, stepName, message, timestamp, type, logOrder, tenantId).run();
|
|
33
52
|
}
|
|
53
|
+
function trySerializeObj(obj, serializer) {
|
|
54
|
+
try {
|
|
55
|
+
return serializer.serialize(obj);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error("Error serializing object:", error);
|
|
58
|
+
return String(obj);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
34
61
|
function tryDeserializeObj(obj, serializer) {
|
|
35
62
|
try {
|
|
36
63
|
return serializer.deserialize(obj);
|
|
@@ -198,26 +225,24 @@ async function createStepContext(context) {
|
|
|
198
225
|
const stepMetadataParam = typeof step$1 === "string" ? void 0 : step$1.metadata;
|
|
199
226
|
if (context.parentInstanceId && reuseSuccessfulSteps) {
|
|
200
227
|
console.warn("temp: try to reuse successful steps");
|
|
201
|
-
const existingStep = await context.
|
|
202
|
-
/* sql */
|
|
203
|
-
`SELECT * FROM StepTable WHERE instanceId = ? AND stepName = ? AND tenantId = ?`
|
|
204
|
-
).bind(context.parentInstanceId, stepNameParam, context.tenantId).first();
|
|
228
|
+
const existingStep = await getStepRecord(context, stepNameParam, context.parentInstanceId);
|
|
205
229
|
if (existingStep) {
|
|
206
230
|
console.warn("temp: found existing step", existingStep);
|
|
207
231
|
const row = existingStep;
|
|
208
232
|
if (row.status === "completed") {
|
|
233
|
+
console.warn("temp: found existing step with completed status", row);
|
|
209
234
|
await insertStepRecordFull(context, {
|
|
210
235
|
instanceId,
|
|
211
236
|
name: row.name,
|
|
212
237
|
status: row.status,
|
|
213
|
-
metadata: row.metadata,
|
|
238
|
+
metadata: trySerializeObj(row.metadata, context.serializer),
|
|
214
239
|
startTime: row.startTime,
|
|
215
240
|
endTime: row.endTime,
|
|
216
241
|
result: row.result,
|
|
217
242
|
error: row.error
|
|
218
243
|
});
|
|
219
244
|
return context.serializer.deserialize(row.result);
|
|
220
|
-
}
|
|
245
|
+
} else console.warn("temp: found existing step with different status", row);
|
|
221
246
|
} else console.warn("temp: no existing step found");
|
|
222
247
|
} else console.warn("temp: not trying to reuse successful steps");
|
|
223
248
|
let waitFor = [];
|