@brandboostinggmbh/observable-workflows 0.4.0 → 0.4.2
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.d.ts +7 -1
- package/dist/index.js +12 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -147,6 +147,8 @@ type StepContextOptions = {
|
|
|
147
147
|
parentInstanceId?: string;
|
|
148
148
|
serializer: Serializer;
|
|
149
149
|
idFactory: () => string;
|
|
150
|
+
/** If true this step context will attempt to reuse results from parent instance steps where possible. Defaults to True */
|
|
151
|
+
reuseSuccessfulSteps?: boolean;
|
|
150
152
|
};
|
|
151
153
|
type ConsoleWrapper = {
|
|
152
154
|
log: (message: string) => void;
|
|
@@ -222,7 +224,7 @@ type WorkflowContextInstance = {
|
|
|
222
224
|
tenantId: string;
|
|
223
225
|
parentInstanceId?: string | undefined;
|
|
224
226
|
}) => Promise<void>;
|
|
225
|
-
retry: <I>(workflow: WorkflowFunction<I>, retryInstanceId: string) => Promise<void>;
|
|
227
|
+
retry: <I>(workflow: WorkflowFunction<I>, retryInstanceId: string, retryOptions?: RetryWorkflowOptions | undefined) => Promise<void>;
|
|
226
228
|
};
|
|
227
229
|
type QueueWorkflowContextOptions = {
|
|
228
230
|
QUEUE: Queue<WorkflowQueueMessage>;
|
|
@@ -256,6 +258,10 @@ type WorkflowQueueMessage = {
|
|
|
256
258
|
tenantId: string;
|
|
257
259
|
retryInstanceId: string;
|
|
258
260
|
};
|
|
261
|
+
type RetryWorkflowOptions = {
|
|
262
|
+
/** If true the retry will attept to reuse all results from successful steps. Defaults to True */
|
|
263
|
+
reuseSuccessfulSteps?: boolean;
|
|
264
|
+
};
|
|
259
265
|
|
|
260
266
|
//#endregion
|
|
261
267
|
//#region src/observableWorkflows/defineWorkflow.d.ts
|
package/dist/index.js
CHANGED
|
@@ -191,16 +191,19 @@ function defineWorkflow(workflow, callback) {
|
|
|
191
191
|
//#region src/observableWorkflows/createStepContext.ts
|
|
192
192
|
async function createStepContext(context) {
|
|
193
193
|
const instanceId = context.instanceId;
|
|
194
|
+
const reuseSuccessfulSteps = context.reuseSuccessfulSteps ?? true;
|
|
194
195
|
await ensureTables(context.D1);
|
|
195
196
|
const step = async (step$1, callback) => {
|
|
196
197
|
const stepNameParam = typeof step$1 === "string" ? step$1 : step$1.name;
|
|
197
198
|
const stepMetadataParam = typeof step$1 === "string" ? void 0 : step$1.metadata;
|
|
198
|
-
if (context.parentInstanceId) {
|
|
199
|
+
if (context.parentInstanceId && reuseSuccessfulSteps) {
|
|
200
|
+
console.warn("temp: try to reuse successful steps");
|
|
199
201
|
const existingStep = await context.D1.prepare(
|
|
200
202
|
/* sql */
|
|
201
203
|
`SELECT * FROM StepTable WHERE instanceId = ? AND stepName = ? AND tenantId = ?`
|
|
202
204
|
).bind(context.parentInstanceId, stepNameParam, context.tenantId).first();
|
|
203
205
|
if (existingStep) {
|
|
206
|
+
console.warn("temp: found existing step", existingStep);
|
|
204
207
|
const row = existingStep;
|
|
205
208
|
if (row.status === "completed") {
|
|
206
209
|
await insertStepRecordFull(context, {
|
|
@@ -215,8 +218,8 @@ async function createStepContext(context) {
|
|
|
215
218
|
});
|
|
216
219
|
return context.serializer.deserialize(row.result);
|
|
217
220
|
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
221
|
+
} else console.warn("temp: no existing step found");
|
|
222
|
+
} else console.warn("temp: not trying to reuse successful steps");
|
|
220
223
|
let waitFor = [];
|
|
221
224
|
const startTime = Date.now();
|
|
222
225
|
const stepStatus = "pending";
|
|
@@ -322,7 +325,7 @@ function createWorkflowContext(options) {
|
|
|
322
325
|
serializer: options.serializer ?? defaultSerializer,
|
|
323
326
|
idFactory: options.idFactory ?? defaultIdFactory
|
|
324
327
|
};
|
|
325
|
-
const call = async ({ workflow, input, workflowName, tenantId, parentInstanceId }) => {
|
|
328
|
+
const call = async ({ workflow, input, workflowName, tenantId, parentInstanceId, reuseSuccessfulSteps }) => {
|
|
326
329
|
if (!ensuredTables) {
|
|
327
330
|
await ensureTables(options.D1);
|
|
328
331
|
ensuredTables = true;
|
|
@@ -362,7 +365,9 @@ function createWorkflowContext(options) {
|
|
|
362
365
|
tenantId,
|
|
363
366
|
instanceId,
|
|
364
367
|
serializer: internalContext.serializer,
|
|
365
|
-
idFactory: internalContext.idFactory
|
|
368
|
+
idFactory: internalContext.idFactory,
|
|
369
|
+
parentInstanceId,
|
|
370
|
+
reuseSuccessfulSteps
|
|
366
371
|
});
|
|
367
372
|
try {
|
|
368
373
|
await workflow._callback(input, {
|
|
@@ -415,7 +420,7 @@ function createWorkflowContext(options) {
|
|
|
415
420
|
throw error;
|
|
416
421
|
}
|
|
417
422
|
};
|
|
418
|
-
const retry = async (workflow, retryInstanceId) => {
|
|
423
|
+
const retry = async (workflow, retryInstanceId, retryOptions) => {
|
|
419
424
|
if (!ensuredTables) {
|
|
420
425
|
await ensureTables(options.D1);
|
|
421
426
|
ensuredTables = true;
|
|
@@ -435,6 +440,7 @@ function createWorkflowContext(options) {
|
|
|
435
440
|
input,
|
|
436
441
|
workflowName: oldWorkflowName ?? "unknown",
|
|
437
442
|
parentInstanceId: retryInstanceId,
|
|
443
|
+
reuseSuccessfulSteps: retryOptions?.reuseSuccessfulSteps,
|
|
438
444
|
tenantId
|
|
439
445
|
});
|
|
440
446
|
};
|