Wants to run a rule 6 times in day

We have created one rule to fetch failed task at every 24 hours.
Now instead of every 24 hours we need output as every 4 hours.

We want to change in code instead of scheduling run rule task.

Hello,

I can think about the below design options:

  1. Within your rule you store the last execution timestamp in the TaskDefintion of the Run Rule task. Then we simply schedule the task every 4 hours and during each execution, we can retrive the failed task between the last execution and current execution time.
  2. Another approach is simply hard code the time window within your rule. For example, we schedule the the task at 4:05, 8:05…, and while execution, it will get the nearest time windonw you defined and retrieve the corresponding failed tasks.

Hope this can somehow helpful in your case.

1 Like

Another option would be to use a Custom object as a persistent data store.

  1. Load the custom object, and then load the list of Failed Tasks from the Custom Object
  2. Run your rule logic and build a List of all failed tasks
  3. Compare the list of failed tasks you loaded from the Custom object in #1 to the List of failed tasks you calculated in #2 - this will tell you what new task failures occurred since the last run
  4. Update the Custom object with the updated list of failed tasks you calculated and built in #2, and save the updated Custom object

Now you can run that rule as often/infrequently as you like, since the rule’s data analysis should be self-sustaining.

Note: I used a List for the failed tasks, but you could also build it to use a Map instead (entry key being the task name and value being the last launched time for example) and base your comparison using the Map containsKey(Object o) method, and double-checking/confirming if it’s a new failure or not by checking the last launch timestamp of the “discovered failed task” from #2 to the value element of the saved failure of a previous run that you loaded into your custom object.

1 Like