Getting better sleep

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.

There are two ways to pause while you are waiting for something in vCO, you can use the javascript System.Sleep() function or you can use a Waiting timer block.

When you use the System.Sleep() function the javascript interpreter is not suspended, it is constancy doing something to see if it’s wait is over, this means that every System.Sleep() that is running is using up resources.

The better alternative is to use the Waiting timer block.

Waiting timer

When you use the Waiting timer block you have to give it a date/time for it to wake back up at. The advantage is that when the workflow is in a suspended state it does not keep a javascript interpreter running and thus saves on resources and lets you have a lot more workflows running at any point in time.

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:

Improved sleep workflow

Improved sleep workflow

 

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:

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.

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.

One thought on “Getting better sleep

  1. Pingback: vRealize Automation – Machine provisioned entered but guest customization still running – SolutionYST

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">