Recommendations on waiting for a condition to happen #1931
-
I have a workflow that needs to hold on a specific step until some other processes update database records. I initially implemented this as a What I want is for this step to execute every so often and only continue onto the next step once the database condition is met (which I could make work by pushing the allowed number of retries really high but that feels like a hack). What is the recommended way for implementing such logic? Should I make the step itself loop and sleep? Is the expectation that the other part of the app will emit a new event and I use Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @jasonroelofs - yes, this is exactly what If you then instrument other parts of your app with events (free our side, and a low implementation cost) you'll automatically resume those functions. Typically, it'd be something like this: await step.waitForEvent("some-step-id", {
event: "api/something.happened", // format: <service>/<noun>
timeout: "12h",
if: `async.data.completion_id == "${someVar}"`,
}); You probably want to store some sort of ID for the matching expression. Without more details, it's hard to know what identifiers you can use to resolve these matches — but this is the general idea! |
Beta Was this translation helpful? Give feedback.
Hey @jasonroelofs - yes, this is exactly what
step.waitForEvent
is for. It'll pause your function, set up a new signal, and automatically resolve whenever the matching event is found.If you then instrument other parts of your app with events (free our side, and a low implementation cost) you'll automatically resume those functions.
Typically, it'd be something like this:
You probably want to store some sort of ID for the matching expression. Without more details, it's hard to know what identifiers you can use to r…