Replies: 2 comments 1 reply
-
disclaimer: it is not implemented yet I think the best approach would be to just allow each step to have "delay" option. When step is started, the delay should be passed to the pgmq.send() so the visibility timeout of a message that is sent to the queue is set to the future and message will only be processed by a workers when the delay passess. API idea for DSL:const minute = 60;
const hour = 60 * minute;
const day = 24 * hour;
new Flow<Input>({ slug: "my_flow" })
.step({ slug: "rootStep1", delay: 15 * minute }, async (input) => {
/* ... */
})
.step({ slug: "rootStep2", delay: 2 * hour }, async (input) => {
/* ... */
})
.step(
{
slug: "otherStep",
dependsOn: ["rootStep1", "rootStep2"],
delay: 3 * day,
},
async (input) => {
/* ... */
},
); Here, when you start this flow, both rootStep1 and rootStep2 messages would be sent immediately, but rootStep1 will be visible after 15 minutes and rootStep2 become visible after 2 hours. Only after those two complete, a message for otherStep is sent, but it will be hidden from the workers for 3 days. Your use caseIn your use case you would only put the delay on the root step (one without dependencies that gets started when the flow starts) and start the flow immediately after user gets inserted. Would that work for you? |
Beta Was this translation helpful? Give feedback.
-
This was just implemented in #182 and was just released to NPM (0.5.3): https://github.com/pgflow-dev/pgflow/releases/tag/%40pgflow%2Fcore%400.5.3 cc @devRokas |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Example 3 step workflow:
Step 1: User gets inserted into a database
Step 2: "Wait" for 24 hours
Step 3: Welcome email is sent to the user
Beta Was this translation helpful? Give feedback.
All reactions