@brandboostinggmbh/observable-workflows 0.4.0 → 0.4.1
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 +8 -4
- 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,11 +191,12 @@ 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) {
|
|
199
200
|
const existingStep = await context.D1.prepare(
|
|
200
201
|
/* sql */
|
|
201
202
|
`SELECT * FROM StepTable WHERE instanceId = ? AND stepName = ? AND tenantId = ?`
|
|
@@ -322,7 +323,7 @@ function createWorkflowContext(options) {
|
|
|
322
323
|
serializer: options.serializer ?? defaultSerializer,
|
|
323
324
|
idFactory: options.idFactory ?? defaultIdFactory
|
|
324
325
|
};
|
|
325
|
-
const call = async ({ workflow, input, workflowName, tenantId, parentInstanceId }) => {
|
|
326
|
+
const call = async ({ workflow, input, workflowName, tenantId, parentInstanceId, reuseSuccessfulSteps }) => {
|
|
326
327
|
if (!ensuredTables) {
|
|
327
328
|
await ensureTables(options.D1);
|
|
328
329
|
ensuredTables = true;
|
|
@@ -362,7 +363,9 @@ function createWorkflowContext(options) {
|
|
|
362
363
|
tenantId,
|
|
363
364
|
instanceId,
|
|
364
365
|
serializer: internalContext.serializer,
|
|
365
|
-
idFactory: internalContext.idFactory
|
|
366
|
+
idFactory: internalContext.idFactory,
|
|
367
|
+
parentInstanceId,
|
|
368
|
+
reuseSuccessfulSteps
|
|
366
369
|
});
|
|
367
370
|
try {
|
|
368
371
|
await workflow._callback(input, {
|
|
@@ -415,7 +418,7 @@ function createWorkflowContext(options) {
|
|
|
415
418
|
throw error;
|
|
416
419
|
}
|
|
417
420
|
};
|
|
418
|
-
const retry = async (workflow, retryInstanceId) => {
|
|
421
|
+
const retry = async (workflow, retryInstanceId, retryOptions) => {
|
|
419
422
|
if (!ensuredTables) {
|
|
420
423
|
await ensureTables(options.D1);
|
|
421
424
|
ensuredTables = true;
|
|
@@ -435,6 +438,7 @@ function createWorkflowContext(options) {
|
|
|
435
438
|
input,
|
|
436
439
|
workflowName: oldWorkflowName ?? "unknown",
|
|
437
440
|
parentInstanceId: retryInstanceId,
|
|
441
|
+
reuseSuccessfulSteps: retryOptions?.reuseSuccessfulSteps,
|
|
438
442
|
tenantId
|
|
439
443
|
});
|
|
440
444
|
};
|