I’m planning to use a cron workflow to schedule tasks periodically. The task runs every 15 minutes and would fan out more workflows consumed by another service.
I have the following questions regarding how to set up the cron:
If I want this cron triggered by only 1 instance at a time and running in a dedicated service. Should I just trigger the cron workflow during service start up time?
If yes to Q1, when I redeploy the service each time, this would mean a new cron workflow will be triggered, if it is using the same workflow id, will this cause failures?
If during the redeployment, I change some config of the workflow, like the cron schedule from 15 min to 5 min, How will Temporal pick up the change and make sure all subsequent runs will execute with the latest version? (I dont care existing scheduled run)?
Is there a good way to stop or pause the cron workflow?
There is no problem triggering workflow by more than one instance. Temporal ensures the uniqueness of workflow executions by their WorkflowId. So if your triggering code is using the same ID then there will be only one workflow execution running. The trigger code should ignore the WorkflowExecutionAlreadyStarted exception which is thrown in the case of duplicated starts.
No problem here.
Currently, there is no way to update a cron workflow schedule directly without stopping the cron workflow. The workarounds are:
3.1. Triggering code can query already running the workflow for its cron schedule and then terminate and start it again if it changed.
3.2. Do not use “cron” workflow feature and implement your own periodic workflow that can check if cron schedule has changed using activity and sleep accordingly. Here is a periodic workflow example. And here is an example of updating timer on the signal which is also relevant.