Active IQ Unified Manager Discussions

How to schedule a workflow for recurring executions: The solution

sinhaa
8,553 Views

Scheduling a workflow for recurring execution has been long awaited in WFA, perhaps from 2.0 time. The following document shows how to get it done. I've also explained the logic behind it. It’s very simple to use, meets every requirement which one can have from a scheduler and of course highly flexible.

 

Let's go!!

 

The Real stuff. What is this? Is this actually a scheduler?

 

No. This is actually a command in your workflow, but a special 'magical' command. This 'magical' command logic is built using the answers for the following questions:

 

  1. Can a workflow be scheduled for a delayed execution in a future time? Yes, but only one execution instance. If you want the next execution, execute the workflow again providing the same set of inputs and the execution date/time.
  2. During workflow execution, can a command inside a workflow get to know what is the  name of the workflow? Yes
  3. During workflow execution, can the command know what is the job execution id? Yes
  4. Is there any programmatic interface available to know what are the user input provided or a particular job execution? Yes
  5. Can a command inside a workflow trigger another workflow? Yes.
  6. Can a command inside the same workflow trigger itself? Absolutely yes.

 

I've ticked all boxes needed to build such a solution. The solution is to make the workflow a smart workflow, so smart that it can schedule itself for the next execution. It no longer needs any other task scheduler to tigger it.

 

WFA provides a large set of REST APIs for other 3rd part SW integration. But I  also can make  good use of these APIs to make smart workflows. I have always believed that WFA should not only be seen as a framework for automating Storage boxes or server, but just about any task( inside a computer of course) which is done manually. WFA is an awesome product indeed.

 

 

So this is a command called "Workflow Scheduler" which  you can put in your workflow as another command.

 

Prerequisites:

 

  1. You need PowerShell 3.0 on your WFA server. I certainly could have done it for PoSH2.0 as well, but life for web interfaces  using PowerShell is so much easier with Posh3.0. Posh3.0 is a big jump from 2.0. WFA is fully supported to work on Posh3.0. Its available by default in Win2012, Win2008 can be upgraded, Win2003 users can't use it.

 

  1. Add credentials of a WFA Admin/Architect in you WFA itself with Name/IP: localhost

 

Match: Exact

Type: Other

Name/IP: localhost

Username: <WFA Admin/Architect Username>

Password: <User Password>

 

 Credentials_localhost.png

 

3.  Minimum WFA version 2.2. This is only needed for Importing the dar. I've provided the command code in text too. The command code is the real deal.

 

How to use it?

 

If you have a workflow which you want for recurring executions, just add this command "Workflow Scheduler" in it. The command takes parameters for the workflow execution intervals. For example minsInterval for executing this workflow every x minutes, or daysInterval for executing the workflow etc.

Now just like a normal workflow execution execute this workflow deciding what is the trigger time.

 

Example: Suppose you want the execution every day at 10:00 PM.

So provide daysInterval = 1

 

And execute the workflow for a delayed execution at 10:00 PM. You can pick the day to start as you wish. The workflow will execute at 10:00 PM and when this execution reaches our magical command "workflow scheduler", this command will trigger the same workflow  with same set of inputs for the next execution at 10:00 PM tomorrow. And so on an so forth.

 

I’ve attached a very simple example workflow here to help you understand.

 

An Example of a workflow scheduled for recurring execution Daily at 11:30 PM starting 10-March-2015

 

 

 Workflow Scheduler.png

 

 

How to stop/suspend this recurring execution?

 

Easy. You just abort the next scheduled job execution in Execution=> Execution Status. The cycle will stop.

 

How to resume it?

 

Easy again. Just resume the same aborted job. The cycle restarts.

 

Can I change the schedule execution time?

 

Yes. After aborting the current execution, you can resume the same workflow at a new time. Execution interval can't be modified as you can't change the command parameters. But the recurring execution now can occur at a new time.

 

Where or which position to place this “workflow scheduler” command in your workflow? At the beginning ? At the end? Or somewhere in the middle.

 

This completely depends on your choice. See some below cases.

 

  1. You don't want the next job execution scheduling to happen if any of the commands in my current workflow execution fails: Put command “workflow scheduler” in the end. It will trigger the schedule of the next job execution only when all real original commands of your workflow have passed. else not.

     

  1. You want continuous job executions irrespective of the workflow command failures: Put it in the beginning. It will trigger the schedule for next execution before any of the actual command begin executing.

     

  1. You want an approval before the next execution job is scheduled: Add an approval point before the comamnd.

     

      So it’s all left to you.

 

     

Can an operator decide the execution schedule?

 

Yes, but which workflows will be available to him/her for this recurring execution will have to be decided by the designer. This is a good thing to have as it serves for access control in a way. The Architect/Admin can now restrict which workflow can be put for recurring executions. Operators can’t execute just any workflow available to him for automatic recurring execution.

 

And the workflow designer can also choose which scheduling parameter is to be made a variable for the operator. For example the designer want the operator to schedule a given workflow only for weeks Interval and not months or days i.e. he/she can only chose to schedule for weekly, biweekly etc. executions and  nothing else. For this the designer can define a User-Input variable only for weeksInterval parameter. It’s Done.

 

You want workflow execution to be scheduled either for daily or once in 2 days but not any other. You can restrict this.

 

Or he/she wants to give full freedom to the operator make his/her own decision about scheduling, he defined user-input variable for all scheduling parameters.

 

The workflow designer wants weekly schedule but the day should not be a weekday: You can even do this.

 

Is this flexible enough for my requirements?

 

I’ve attached the very command code. You can modify the command as per your requirements.

 

Suppose you want daily execution of a certain workflow at 10:00 PM but skip a day of execution if the day is a Monday. Modify the code check for the day and add another day if it’s a Monday. Its posh code and highly readable.

 

So you can see how this can be used in a  variety of ways. This is the beauty of a programmatic solution. Its highly flexible, it allows users to design solution based on their requirements.

 

Flexibility is the heart & soul of WFA. Thats why I like it.

 

I have a workflow but I don't want to modify it by adding a new command in it. Can I still use this solution?

 

Yes but with WFA 3.0 on wards. WFA3.0 allows to create modular workflows. Create a parent workflow with you actual workflow as a child workflow in it. Add our “workflow scheduler” command too. So now you don't need to touch your existing workflow. I've attached a workflow example here.

 

 

 

Have fun!!

 

sinhaa

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
3 REPLIES 3

sinhaa
8,095 Views

Providing a new version 1.1.0 of the command "WFA Schedular"

 

Changes made:

 

  1. Added conditional String Representation based on the Scheduling parameter provided. 
  2. Provided check for the right number of parameters passed into the command.
  3. Added a new parameter "Expiry Date" to automatically stop the recurring execution upon expiry.
  4. Check for Posh3.0 version in code.

Have Fun!!

 

sinhaa

 

Below example for:

Schedule a workflow for recurring execution every alternate day i.e. once in 2 days at 10:30 PM starting 06-Jul-2015 (Today's date is 02-Jul-2015) . The recurring workflow execution  should expire on 31-Dec-2015 and stop.

 

Untitled.png

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Peta
7,943 Views

This is a great workflow, thank you.

 

Will you be making the same updates to the WFA3.0 version?

sinhaa
7,897 Views

Hi Peta,

   

       A WFA content is always forward or upward compatible. So a content created for WFA2.2 will work without any issues on a WFA3.0 and above.

 

The workflow WFA2_2_Workflow_for_Recurring_Execution_version1_0_2.dar will work on WFA3.0 without any isses. The workflow is a sample to help you understand how to use it. The real deal is the command "Workflow Scheduler" in this workflow. I ealier had also  given a WFA 3.0 version just to show how to use the command in a Modular workflow ( available only from WFA3.0 and not below ). 

 

So put teh command any of your workflows and get it going.

 

warm regards,

Sinhaa

 

 

 

 

 

 

 

 

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
Public