VMware Cloud Community
msamadzadegan
Contributor
Contributor
Jump to solution

Schedule WorkFlow in Custom Time

Hi,

How can i schedule a work flow in custom time?

I want schedule my work flow every two week in Thursday.

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

"Every 2 weeks on Thursday" is a type of recurrence that cannot be expressed in current vRO scheduler UI.

Not sure if they are applicable to your case, but here are some possible workarounds:

  • Create a recurrence "Every week on Thursday". This way, your workflow will be executed twice as often, so you'll have to add some additional code in the workflow to check if the current Thursday is 'right' or 'wrong' Thursday (eg. by computing the current week number since some start date, and considering odd week numbers as 'wrong' and even week numbers as 'right'), and then either continue with the normal workflow execution or exit.
  • Use a more flexible external scheduler; eg. Linux cron job plus a small script to run your workflow.
  • Schedule the workflow without a recurrence, then add some code in your workflow that will compute the date of the Thursday after 2 weeks and reschedule itself at that date using the scripting method Workflow.schedule(...).

View solution in original post

Reply
0 Kudos
4 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

"Every 2 weeks on Thursday" is a type of recurrence that cannot be expressed in current vRO scheduler UI.

Not sure if they are applicable to your case, but here are some possible workarounds:

  • Create a recurrence "Every week on Thursday". This way, your workflow will be executed twice as often, so you'll have to add some additional code in the workflow to check if the current Thursday is 'right' or 'wrong' Thursday (eg. by computing the current week number since some start date, and considering odd week numbers as 'wrong' and even week numbers as 'right'), and then either continue with the normal workflow execution or exit.
  • Use a more flexible external scheduler; eg. Linux cron job plus a small script to run your workflow.
  • Schedule the workflow without a recurrence, then add some code in your workflow that will compute the date of the Thursday after 2 weeks and reschedule itself at that date using the scripting method Workflow.schedule(...).
Reply
0 Kudos
msamadzadegan
Contributor
Contributor
Jump to solution

Thank you,

Please write a example of workflow.schedule method.

i want use it but can not write it in correct format

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Something like the following should work - it demonstrates how to schedule a workflow for one-off execution after 14 days from now.

var wfToSchedule = workflow.rootWorkflow; // schedule itself (the current executing workflow)

//var wfToSchedule = Server.getWorkflowWithId("3689db6f-f9b3-4048-80cd-7dd2834d1d90"); // schedule a workflow with given ID

// Determine the schedule date (in this case, 14 days after now)

var scheduleDate = new Date();

var after = 14 * 24 * 60 * 60 * 1000; // 14 days in milliseconds

scheduleDate.setTime(scheduleDate.getTime() + after);

// Prepare workflow input parameters (if any)

var wfInputs = new Properties();

wfInputs.put("p1", "some value");

var task = wfToSchedule.schedule(wfInputs, scheduleDate, "myusername", "mypassword");

Reply
0 Kudos
msamadzadegan
Contributor
Contributor
Jump to solution

Thank You, It's work.Smiley Happy

Reply
0 Kudos