@brandboostinggmbh/observable-workflows 0.20.3-beta.1 → 0.21.1-beta.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 +5 -3
- package/dist/index.js +19 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -686,12 +686,14 @@ type WorkflowFunction<INPUT, OUTPUT, TYPE extends string = string> = {
|
|
|
686
686
|
* Use either the WorkflowContect, or the QueueWorkflowContext to run or enqueue this. */
|
|
687
687
|
_callback: (input: INPUT, ctx: WorkflowContext) => Promise<OUTPUT>;
|
|
688
688
|
};
|
|
689
|
-
type WorkflowEnqueueBatchItem<I, O> = {
|
|
690
|
-
workflow: WorkflowFunction<I, O>;
|
|
689
|
+
type WorkflowEnqueueBatchItem<I, O, TYPE extends string = string> = {
|
|
690
|
+
workflow: WorkflowFunction<I, O, TYPE>;
|
|
691
691
|
tenantId: string;
|
|
692
692
|
input: I;
|
|
693
693
|
initialName: string;
|
|
694
694
|
dependencies?: WorkflowDependency[];
|
|
695
|
+
/** Optional trigger identifier for workflow correlation. If not provided, one will be auto-generated. */
|
|
696
|
+
triggerId?: string | null;
|
|
695
697
|
};
|
|
696
698
|
type WorkflowQueueMessage = {
|
|
697
699
|
type: 'workflow-run';
|
|
@@ -874,7 +876,7 @@ declare const createLogAccessor: (context: {
|
|
|
874
876
|
//#endregion
|
|
875
877
|
//#region src/observableWorkflows/createQueueWorkflowContext.d.ts
|
|
876
878
|
declare function createQueueWorkflowContext(options: QueueWorkflowContextOptions): {
|
|
877
|
-
enqueueWorkflow: <I, O, TYPE extends string>(
|
|
879
|
+
enqueueWorkflow: <I, O, TYPE extends string>(params: WorkflowEnqueueBatchItem<I, O, TYPE>) => Promise<ScheduledWorkflowExecutionStub<O, TYPE>>;
|
|
878
880
|
enqueueWorkflowBatch: <I, O>(workflows: Array<WorkflowEnqueueBatchItem<I, O>>) => Promise<Array<ScheduledWorkflowExecutionStub<O, string>>>;
|
|
879
881
|
enqueueRetryWorkflow: <I, O>(workflow: WorkflowFunction<I, O>, tenantId: string, oldInstanceId: string, reuseSuccessfulSteps?: boolean) => Promise<void>;
|
|
880
882
|
handleWorkflowQueueMessage: ({
|
package/dist/index.js
CHANGED
|
@@ -1518,6 +1518,10 @@ const createLogAccessor = (context) => {
|
|
|
1518
1518
|
}
|
|
1519
1519
|
return [];
|
|
1520
1520
|
};
|
|
1521
|
+
/**
|
|
1522
|
+
* Gets all workflows that have the given parentInstanceId. This is a shallow get - only returns
|
|
1523
|
+
* base workflow data without steps, logs, properties, or dependencies.
|
|
1524
|
+
*/
|
|
1521
1525
|
const getWorkflowByParentId = async (parentInstanceId) => {
|
|
1522
1526
|
const result = await retryD1Operation(() => context.D1.prepare(`SELECT * FROM WorkflowTable WHERE parentInstanceId = ? AND tenantId = ?`).bind(parentInstanceId, context.tenantId).all(), context.retryConfig);
|
|
1523
1527
|
if (result.results) {
|
|
@@ -1530,6 +1534,11 @@ const createLogAccessor = (context) => {
|
|
|
1530
1534
|
}
|
|
1531
1535
|
return null;
|
|
1532
1536
|
};
|
|
1537
|
+
/**
|
|
1538
|
+
* Gets a workflow by its triggerId. This is a shallow get - only returns base workflow data
|
|
1539
|
+
* without steps, logs, properties, retries, or dependencies.
|
|
1540
|
+
* Use getWorkflow(instanceId) if you need the full workflow with all related data.
|
|
1541
|
+
*/
|
|
1533
1542
|
const getWorkflowByTriggerId = async (triggerId) => {
|
|
1534
1543
|
const result = await retryD1Operation(() => context.D1.prepare(`SELECT * FROM WorkflowTable WHERE triggerId = ? AND tenantId = ?`).bind(triggerId, context.tenantId).first(), context.retryConfig);
|
|
1535
1544
|
if (result) {
|
|
@@ -1775,8 +1784,9 @@ function createQueueWorkflowContext(options) {
|
|
|
1775
1784
|
idFactory: options.idFactory ?? defaultIdFactory
|
|
1776
1785
|
};
|
|
1777
1786
|
const idFactory = internalContext.idFactory;
|
|
1778
|
-
const enqueueWorkflow = async (
|
|
1779
|
-
const triggerId =
|
|
1787
|
+
const enqueueWorkflow = async (params) => {
|
|
1788
|
+
const { workflow, tenantId, input, initialName, dependencies, triggerId: providedTriggerId } = params;
|
|
1789
|
+
const triggerId = providedTriggerId ?? idFactory();
|
|
1780
1790
|
const instanceId = idFactory();
|
|
1781
1791
|
const startTime = Date.now();
|
|
1782
1792
|
if (dependencies && dependencies.length > 0) await insertWorkflowRecord(internalContext, {
|
|
@@ -1845,19 +1855,20 @@ function createQueueWorkflowContext(options) {
|
|
|
1845
1855
|
* **Network requests:** 2 + M, where M is the number of workflows with large inputs
|
|
1846
1856
|
* that require external blob storage.
|
|
1847
1857
|
*
|
|
1848
|
-
* **
|
|
1849
|
-
*
|
|
1850
|
-
* For very large batches, consider splitting into smaller chunks.
|
|
1858
|
+
* **Batch size limit:** A maximum of 100 workflows can be enqueued in a single batch.
|
|
1859
|
+
* Exceeding this limit will throw an error. For larger sets, split into chunks of 100 or fewer.
|
|
1851
1860
|
*
|
|
1852
|
-
* @
|
|
1861
|
+
* @throws {Error} If `workflows.length` exceeds 100
|
|
1862
|
+
* @param workflows - Array of workflow items to enqueue (max 100)
|
|
1853
1863
|
* @returns Array of scheduled workflow stubs in the same order as inputs
|
|
1854
1864
|
*/
|
|
1855
1865
|
const enqueueWorkflowBatch = async (workflows) => {
|
|
1866
|
+
if (workflows.length > 100) throw new Error(`enqueueWorkflowBatch: Cannot enqueue more than 100 workflows in a single batch (received ${workflows.length}). Split into smaller chunks.`);
|
|
1856
1867
|
const startTime = Date.now();
|
|
1857
1868
|
console.log(`enqueueWorkflowBatch: Starting batch of ${workflows.length} workflows`);
|
|
1858
|
-
const preparedWorkflows = await Promise.all(workflows.map(async ({ workflow, tenantId, input, initialName, dependencies }) => {
|
|
1869
|
+
const preparedWorkflows = await Promise.all(workflows.map(async ({ workflow, tenantId, input, initialName, dependencies, triggerId: providedTriggerId }) => {
|
|
1859
1870
|
const instanceId = idFactory();
|
|
1860
|
-
const triggerId = idFactory();
|
|
1871
|
+
const triggerId = providedTriggerId ?? idFactory();
|
|
1861
1872
|
const hasDependencies = dependencies && dependencies.length > 0;
|
|
1862
1873
|
const prepared = await prepareWorkflowInsertStatements(internalContext, {
|
|
1863
1874
|
instanceId,
|