One lesson I learned a while back is that there is a limit to the number of active workflows that are running in vCO, once you get over a certain amount it got unstable.
The better alternative is to use the Waiting timer block.
So what are the drawbacks?
For one, you have to calculate the date/time when you want it to wake back up, which means that it takes two blocks, one to figure out the time and one to sleep, but that’s not a big deal.
The bigger issue is that (from what I can tell) you can’t do this in an action, you have to drag the Waiting timer block into the designer, this means that things that would be much better suited as actions now have to be workflows.
Another issue is that if the vCO server is restarted while a workflow is in a suspended state and starts back up after the date/time it should wake back up at you may run in to issues. Prior to 5.5 (at least the build that i was working with, i’m not sure what the actual build that fixed this issue is) the workflow would just sit there forever and never resume. In the latest versions this has been fixed and the Waiting timer block now throws an error (“Timeout on signal“) if the time is in the past, which in turns mean that you have to handle that and resume waiting for the time you needed to wait for.
This is what I came up with:
So what is going on here?
First I check to see if we are waiting less than 5 seconds and if so I just use a regular System.Sleep() call.
If we are waiting longer then i create a date/time object that is the specified number of seconds in to the future:
// System.log("Delay is greater than 5 seconds, suspending workflow while waiting.");
var timerDate = new Date((new Date()).getTime() + delay * 1000);
The second part of this is where we handle the workflow being restarted due to a server restart.
Using a decision block I check to see if the error thrown is “Timeout on signal“, which is what it throws if the workflow was restarted.
return (errorCode == "Timeout on signal") ;
If it was something other than that then I fail out of the workflow because we had some other error.
If it was due to a restarted workflow I then check to see if the time we are waiting for is still in the future and if so we go back in to the Waiting timer block.
I have been using this for a couple of months now on vCO 5.5 and I have not had any issues with it, if you have a need for having many workflows waiting for things then give this a shot and let me know how it works for you.
You can download it here.