SleepUntil

Hey everyone! I'm using sleepUntil in my workflow, but when the end time is reached, the entire workflow restarts instead of resuming from the sleep step. Because of this, the sleepUntil action never completes or fails. As a result, my code detects that the step is still pending and triggers sleepUntil again, causing it to re-execute continuously.
No description
9 Replies
Olga Silva
Olga Silva4d ago
Hey! How exactly is your workflow? Is it something like this at the top level (run function)?
await step.sleep("1 minute");
await step.do(something);
await step.sleepUntil(...);
await step.sleep("1 minute");
await step.do(something);
await step.sleepUntil(...);
avenceslau
avenceslau4d ago
Hey @ByteBeast , how are you naming your step.sleepUntil? Regardless, workflow instances do "restart" when sleeps end. Only top level code (code outside of steps) re-runs, step.dos, that have already ran do not run again, sleeps, and waits do not restart. Maybe parts of our Rules of Workflows can help: - Naming steps: https://developers.cloudflare.com/workflows/build/rules-of-workflows/#avoid-doing-side-effects-outside-of-a-stepdo - Avoiding top level side effects: https://developers.cloudflare.com/workflows/build/rules-of-workflows/#avoid-doing-side-effects-outside-of-a-stepdo
ByteBeast
ByteBeastOP4d ago
I have named step deterministic like this "delay-${nodeId}-calculate-time" But in workflow intance it get sufix -1 -2 automatically I have some steps and it's id, which is unique for every step. I am trying to build workflow app, user can define delay and steps. using for loop I reginstered step.do or step.sleepUntil and wait for that sleep to get completed, now the issue is for small delay it's working fine but for last delay like delay of tomorrow 9:00AM from today 4PM I am facing issue. at 9:00AM workflow get's awake but not from the step I let it to sleep. workflow starts all over again, and that fine but you can see in screen shot that sleepuntil did not completed even after it reaches to end time
ByteBeast
ByteBeastOP4d ago
This is my workflow instace which initiate 2 days ago on friday and 3rd sleep should get completed at 15th of Nov at 03:35 but it still runing, and my logic is base on that if previos step get's completed then only execute next step and this causes an issue of infinity loop of sleep, my code for sleepUntill is as below await step.sleepUntil(delay-${nodeId}-sleep, targetTimestamp);
No description
ByteBeast
ByteBeastOP4d ago
And according to documentation if I pass same name to two different do, second do should return me cached value of first do as because name of do is same but this is not happening, it making suffix of -1, -2 for same name, can I prevent that?
avenceslau
avenceslau4d ago
Can you share your workflow code? (If you prefer feel free to send it via DM)
ByteBeast
ByteBeastOP4d ago
@avenceslau Send you in DM
avenceslau
avenceslau4d ago
Will take a look in a bit
ByteBeast
ByteBeastOP4d ago
Okay

Did you find this page helpful?