@redflow/client 0.0.2 → 0.0.3
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/README.md +10 -0
- package/package.json +1 -1
- package/src/types.ts +1 -1
- package/src/worker.ts +16 -7
- package/tests/redflow.e2e.test.ts +41 -0
package/README.md
CHANGED
|
@@ -105,6 +105,16 @@ const analyticsRunId = await step.emitWorkflow(
|
|
|
105
105
|
);
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
+
You can also pass a workflow name string:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
const analyticsRunId = await step.emitWorkflow(
|
|
112
|
+
{ name: "emit-analytics" },
|
|
113
|
+
"analytics-consumer",
|
|
114
|
+
{ orderId: input.orderId, totalCents: input.totalCents },
|
|
115
|
+
);
|
|
116
|
+
```
|
|
117
|
+
|
|
108
118
|
## Run workflows
|
|
109
119
|
|
|
110
120
|
The object returned by `defineWorkflow(...)` has `.run(...)`.
|
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -113,7 +113,7 @@ export type StepApi = {
|
|
|
113
113
|
workflow: WorkflowLike<TInput, TOutput>,
|
|
114
114
|
input: TInput,
|
|
115
115
|
): Promise<TOutput>;
|
|
116
|
-
emitWorkflow(options: StepEmitWorkflowOptions, workflow: WorkflowLike, input: unknown): Promise<string>;
|
|
116
|
+
emitWorkflow(options: StepEmitWorkflowOptions, workflow: WorkflowLike | string, input: unknown): Promise<string>;
|
|
117
117
|
};
|
|
118
118
|
|
|
119
119
|
export type RunState = {
|
package/src/worker.ts
CHANGED
|
@@ -694,18 +694,27 @@ async function processRun(args: {
|
|
|
694
694
|
};
|
|
695
695
|
|
|
696
696
|
const emitWorkflowStep: StepApi["emitWorkflow"] = async (options, workflow, workflowInput) => {
|
|
697
|
+
const workflowName = typeof workflow === "string" ? workflow : workflow.name;
|
|
697
698
|
const idempotencyKey =
|
|
698
|
-
options.idempotencyKey ?? defaultStepWorkflowIdempotencyKey(runId, options.name,
|
|
699
|
+
options.idempotencyKey ?? defaultStepWorkflowIdempotencyKey(runId, options.name, workflowName);
|
|
699
700
|
|
|
700
701
|
return await runStep(
|
|
701
702
|
{ name: options.name, timeoutMs: options.timeoutMs },
|
|
702
703
|
async () => {
|
|
703
|
-
const handle =
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
704
|
+
const handle =
|
|
705
|
+
typeof workflow === "string"
|
|
706
|
+
? await client.runByName(workflow, workflowInput, {
|
|
707
|
+
runAt: options.runAt,
|
|
708
|
+
queueOverride: options.queueOverride,
|
|
709
|
+
idempotencyTtl: options.idempotencyTtl,
|
|
710
|
+
idempotencyKey,
|
|
711
|
+
})
|
|
712
|
+
: await workflow.run(workflowInput, {
|
|
713
|
+
runAt: options.runAt,
|
|
714
|
+
queueOverride: options.queueOverride,
|
|
715
|
+
idempotencyTtl: options.idempotencyTtl,
|
|
716
|
+
idempotencyKey,
|
|
717
|
+
});
|
|
709
718
|
return handle.id;
|
|
710
719
|
},
|
|
711
720
|
);
|
|
@@ -532,6 +532,47 @@ test("step.runWorkflow: same queue avoids self-deadlock with concurrency 1", asy
|
|
|
532
532
|
redis.close();
|
|
533
533
|
}, { timeout: 20_000 });
|
|
534
534
|
|
|
535
|
+
test("step.emitWorkflow: supports workflow name strings", async () => {
|
|
536
|
+
const prefix = testPrefix();
|
|
537
|
+
const redis = new RedisClient(redisServer.url);
|
|
538
|
+
const client = createClient({ redis, prefix });
|
|
539
|
+
setDefaultClient(client);
|
|
540
|
+
|
|
541
|
+
defineWorkflow("child-emit-by-name", { queue: "q_emit_name_child" }, async ({ input }) => {
|
|
542
|
+
return { ok: true, input };
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
const parent = defineWorkflow("parent-emit-by-name", { queue: "q_emit_name_parent" }, async ({ step }) => {
|
|
546
|
+
const childRunId = await step.emitWorkflow(
|
|
547
|
+
{ name: "emit-child-by-name" },
|
|
548
|
+
"child-emit-by-name",
|
|
549
|
+
{ value: 1 },
|
|
550
|
+
);
|
|
551
|
+
|
|
552
|
+
return { childRunId };
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
const worker = await startWorker({
|
|
556
|
+
redis,
|
|
557
|
+
prefix,
|
|
558
|
+
queues: ["q_emit_name_parent", "q_emit_name_child"],
|
|
559
|
+
concurrency: 2,
|
|
560
|
+
runtime: { leaseMs: 500 },
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
try {
|
|
564
|
+
const parentHandle = await parent.run({});
|
|
565
|
+
const parentOut = await parentHandle.result({ timeoutMs: 8000 });
|
|
566
|
+
expect(typeof parentOut.childRunId).toBe("string");
|
|
567
|
+
|
|
568
|
+
const childOut = await client.makeRunHandle(parentOut.childRunId).result({ timeoutMs: 8000 });
|
|
569
|
+
expect(childOut).toEqual({ ok: true, input: { value: 1 } });
|
|
570
|
+
} finally {
|
|
571
|
+
await worker.stop();
|
|
572
|
+
redis.close();
|
|
573
|
+
}
|
|
574
|
+
}, { timeout: 20_000 });
|
|
575
|
+
|
|
535
576
|
|
|
536
577
|
|
|
537
578
|
test("retries: step results are cached across attempts", async () => {
|