@brandboostinggmbh/observable-workflows 0.16.4 → 0.17.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 +3 -0
- package/dist/index.js +12 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -368,6 +368,7 @@ type QueueWorkflowContextOptions = {
|
|
|
368
368
|
QUEUE: Queue<WorkflowQueueMessage>;
|
|
369
369
|
workflowContext: WorkflowContextInstance;
|
|
370
370
|
idFactory?: () => string;
|
|
371
|
+
queueIdentifier: string;
|
|
371
372
|
};
|
|
372
373
|
type HandleWorkflowQueueMessageParams = {
|
|
373
374
|
message: WorkflowQueueMessage;
|
|
@@ -405,6 +406,7 @@ type WorkflowQueueMessage = {
|
|
|
405
406
|
tenantId: string;
|
|
406
407
|
input: any;
|
|
407
408
|
triggerId?: string | null;
|
|
409
|
+
queueIdentifier?: string;
|
|
408
410
|
} | {
|
|
409
411
|
type: 'workflow-retry';
|
|
410
412
|
workflowType: string;
|
|
@@ -413,6 +415,7 @@ type WorkflowQueueMessage = {
|
|
|
413
415
|
triggerId?: string | null;
|
|
414
416
|
/** If true the workflow will attempt to reuse all results from successful steps. Defaults to True */
|
|
415
417
|
reuseSuccessfulSteps?: boolean;
|
|
418
|
+
queueIdentifier?: string;
|
|
416
419
|
};
|
|
417
420
|
type RetryWorkflowOptions = {
|
|
418
421
|
/** If true the retry will attept to reuse all results from successful steps. Defaults to True */
|
package/dist/index.js
CHANGED
|
@@ -1022,7 +1022,8 @@ function createQueueWorkflowContext(options) {
|
|
|
1022
1022
|
workflowName: initialName,
|
|
1023
1023
|
input,
|
|
1024
1024
|
tenantId,
|
|
1025
|
-
triggerId
|
|
1025
|
+
triggerId,
|
|
1026
|
+
queueIdentifier: options.queueIdentifier
|
|
1026
1027
|
});
|
|
1027
1028
|
};
|
|
1028
1029
|
const enqueueRetryWorkflow = async (workflow, tenantId, oldInstanceId, reuseSuccessfulSteps) => {
|
|
@@ -1033,7 +1034,8 @@ function createQueueWorkflowContext(options) {
|
|
|
1033
1034
|
retryInstanceId: oldInstanceId,
|
|
1034
1035
|
tenantId,
|
|
1035
1036
|
triggerId,
|
|
1036
|
-
reuseSuccessfulSteps: reuseSuccessfulSteps ?? true
|
|
1037
|
+
reuseSuccessfulSteps: reuseSuccessfulSteps ?? true,
|
|
1038
|
+
queueIdentifier: options.queueIdentifier
|
|
1037
1039
|
});
|
|
1038
1040
|
};
|
|
1039
1041
|
const enqueueWorkflowBatch = async (workflows) => {
|
|
@@ -1043,12 +1045,14 @@ function createQueueWorkflowContext(options) {
|
|
|
1043
1045
|
workflowName: initialName,
|
|
1044
1046
|
input,
|
|
1045
1047
|
tenantId,
|
|
1046
|
-
triggerId: idFactory()
|
|
1048
|
+
triggerId: idFactory(),
|
|
1049
|
+
queueIdentifier: options.queueIdentifier
|
|
1047
1050
|
} })));
|
|
1048
1051
|
};
|
|
1049
1052
|
const handleWorkflowQueueMessage = async ({ message, env, workflowResolver }) => {
|
|
1050
1053
|
const workflowFunction = workflowResolver(message.workflowType);
|
|
1051
1054
|
if (!workflowFunction) throw new Error(`Workflow ${message.workflowType} not found`);
|
|
1055
|
+
if (message.queueIdentifier != null && message.queueIdentifier !== options.queueIdentifier) console.warn(`Workflow ${message.workflowType} is not in the correct queue handler. It should be handled by queue ${message.queueIdentifier}.`);
|
|
1052
1056
|
const wfc = options.workflowContext;
|
|
1053
1057
|
if (message.type === "workflow-run") {
|
|
1054
1058
|
console.log("running workflow", message.input);
|
|
@@ -1502,17 +1506,21 @@ const createCleanupManager = (context) => {
|
|
|
1502
1506
|
deletedExternalStorageKeysCount: 0
|
|
1503
1507
|
};
|
|
1504
1508
|
const deletedWorkflows = await getAffectedWorkflows(config, limit);
|
|
1509
|
+
console.log(`Deleting ${deletedWorkflows.length} old workflows...`);
|
|
1505
1510
|
const deletedSteps = await getAffectedSteps(config, limit);
|
|
1511
|
+
console.log(`Deleting ${deletedSteps.length} associated steps...`);
|
|
1506
1512
|
let deletedExternalStorageKeysCount = 0;
|
|
1507
1513
|
if (config.deleteRefsFromExternalStorage && context.externalBlobStorage) {
|
|
1508
1514
|
const externalKeys = collectExternalStorageKeys(deletedWorkflows, deletedSteps);
|
|
1509
1515
|
if (externalKeys.length > 0) try {
|
|
1516
|
+
console.log(`Deleting ${externalKeys.length} external storage keys...`);
|
|
1510
1517
|
deletedExternalStorageKeysCount = await context.externalBlobStorage.delete(...externalKeys);
|
|
1511
1518
|
} catch (error) {
|
|
1512
1519
|
console.warn(`Failed to delete some external storage keys: ${error instanceof Error ? error.message : String(error)}`);
|
|
1513
1520
|
}
|
|
1514
1521
|
}
|
|
1515
1522
|
if (deletedWorkflows.length > 0) {
|
|
1523
|
+
console.log(`Proceeding to delete workflows from the database...`);
|
|
1516
1524
|
await context.D1.prepare(`PRAGMA foreign_keys = ON`).run();
|
|
1517
1525
|
let totalDeletedCount = 0;
|
|
1518
1526
|
for (let i = 0; i < deletedWorkflows.length; i += 100) {
|
|
@@ -1532,7 +1540,7 @@ const createCleanupManager = (context) => {
|
|
|
1532
1540
|
deletedSteps,
|
|
1533
1541
|
deletedExternalStorageKeysCount
|
|
1534
1542
|
};
|
|
1535
|
-
}
|
|
1543
|
+
} else console.log(`No workflows matched the deletion criteria.`);
|
|
1536
1544
|
return {
|
|
1537
1545
|
deletedCount: 0,
|
|
1538
1546
|
deletedSteps,
|