Super basic question to confirm the behavior of Workflow.sleep(). Sleeping a workflow just suspends the workflow to be picked up after a set duration, correct? It doesn’t hold on to an active thread and block as it sleeps, right?
Are there any gotchas with the timeouts when executing sleeps in a workflow? Would the sleep time count toward any of the timeout thresholds?
Super basic question to confirm the behavior of Workflow.sleep(). Sleeping a workflow just suspends the workflow to be picked up after a set duration, correct? It doesn’t hold on to an active thread and block as it sleeps, right?
Whenever a workflow is blocked (including blocked due to workflow.sleep) then it should not take any resources on the worker. We do keep these workflows in a cache, so it might look like it is taking some resources but it will be pushed out of the cache if another active workflow comes in and we don’t have space in the cache. The cache size on the worker is configurable.
Are there any gotchas with the timeouts when executing sleeps in a workflow? Would the sleep time count toward any of the timeout thresholds?
I’m not sure I understand this question. Can you provide a concrete scenario on what do you mean by “sleep time count toward any of the timeout thresholds”?
To clarify, let’s say I have a workflow which loops and performs a task then sleeps for some time. Each loop takes ~5 min to perform its tasks and then I sleep for 24 hours and do the same task tomorrow. Let’s say it loops 10 times.
What should I use for my timeout here? Should the WorkflowRunTimeout be something on the order of magnitude of 5m? Or does the entire 10 loop execution count toward this timeout? And do the sleeps factor into the timeout as well or are they excluded since the workflow isn’t actually running during the sleeps?
I’m making an assumption that you want to configure a workflow with a cron schedule to run everyday. In that case it does not matter how long a single run of workflow takes. You should configure the workflow run timeout to something which makes sense for single run of the cron workflow. For example if you believe the single run to take 1 hour at maximum then you should set the timeout to 1 hour.
Once the cron workflow starts running it will run your user code and once workflow completes it computes the delta based on your cron schedule and creates a timer internally to start the next run on the scheduled interval.
Gotcha. Your assumption is mostly correct. I am taking a workflow that was using a cron and switching it to do a loop + sleep because it gives us flexibility if we need to update the delays mid run. I suspected that the cron was not much more than syntactic sugar for a loop + sleep workflow. Thanks for the info!