How to address several running instances of a workflow

2 Replies
Mastra Triager
Mastra Triager2mo ago
GitHub
[DISCORD:1417083124378238986] How to address several running instan...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1417083124378238986 Suppose, I have a workflow with waitForEvent step: import { createWorkflow, createStep...
_roamin_
_roamin_2mo ago
Hi, @dashan108 ! Let me check something, but I think you'll need to use the runId as welll After checking, you'll need to save the runId from the first run so that you can reuse it when sending the event:
const run1 = await mainWorkflow.createRunAsync();
const firstRunId = run1.runId;

run1.start({
inputData: {
// ....
},
});

// later, in your webhook handler
const run2 = await mainWorkflow.createRunAsync({ runId: firstRunId });
const result2 = await run2.sendEvent("test-event", {
// ...
});
const run1 = await mainWorkflow.createRunAsync();
const firstRunId = run1.runId;

run1.start({
inputData: {
// ....
},
});

// later, in your webhook handler
const run2 = await mainWorkflow.createRunAsync({ runId: firstRunId });
const result2 = await run2.sendEvent("test-event", {
// ...
});
Also, one thing to consider is that you can manually set the runId if that's easier for you to manage.
const myRunId = "my-custom-run-id";
const run1 = await mainWorkflow.createRunAsync({ runId: myRunId });
// ...
const run2 = await mainWorkflow.createRunAsync({ runId: myRunId });
const myRunId = "my-custom-run-id";
const run1 = await mainWorkflow.createRunAsync({ runId: myRunId });
// ...
const run2 = await mainWorkflow.createRunAsync({ runId: myRunId });

Did you find this page helpful?