Following up a series of questions around setting timers in the Oracle Community forums, I decided to write this article to try and guide their use and how these can be used to control process execution.
The Use Case
We’ll begin by setting up the scenario in which we’ll have to control our process flow.
Imagine that you want to have a part of your process that executes immediately if the current time is between 08:00am and 04:00pm (16:00 hours for us Europeans), or wait until 08:00am if it’s outside that interval.
It’s frequent to have some kind of control in parts of the processes, for instance when you want to send SMS to your customers. You certainly don’t want to do it at 03:00am.
How will we make this?
We should use a Catch Timer event, of course, and XPATH’s DateTime functions to check the current time and to set the timer to way for next morning’s 08:00.
The Catch Timer event has several ways to be configured (triggered at specific dates and times, on a specific schedule – every day at 10:28:00 (repeatable), or in a time cycle – every 2 minutes), but we’ll focus on the one where we configure the timer to wait for a specific time and date. More on the others perhaps in another article.
We’ll illustrate the use of timers with an example process. You can, of course, adapt it to your needs.
Defining the execution conditions
So you start by defining a gateway that will split the execution between:
- Wait for 08:00am
- This will have to be split into prior to midnight and after midnight. but for now, we’ll consider the scenario of only two options.
So, you set the expression on the conditional flow that will do the immediate execution, leaving the condition that must wait for 08:00 as the unconditional (default) branch.
The expression should be something like this:
xp20:hours-from-dateTime(xp20:current-dateTime()) >= 8 and xp20:hours-from-dateTime(xp20:current-dateTime()) <= 16
The function xp20:current-dateTime() gets the current Date and Time of when the decision is evaluated.
The function xp20:hours-from-dateTime(xs:dateTime) gets the ‘Hours’ integer from a dateTime object.
So you check if the current time is after 08:00am and before 04:00pm.
- If it is, it follows the Green Light path, i.e. the immediate execution path.
- If not, it will follow the Red Light path, and will wait on the timer for a green light (until 08:00am the next day, as per the requirements)
For the test process comprehension, check the process flow below.
So, only one more step to go: Setting the timer to the next 08:00am available.
This is achieved by setting the Timer implementation first to Type=Time Date (red arrow) and then setting the appropriate XPATH expression (orange arrow)
The XPATH expression is as follows:
The add-dayTimeDuration-to-dateTime(xs:dateTime,formattingString) function adds an interval of date/time to a dateTime object.
The interval is set using the format ‘PyyYmmMddDThhHmmMssS‘.
The xp20:current-date() function returns the current date without the time associated, meaning it considers time = 00:00:00.
So, we’re stating that we want to add to the current date the amount of 01 day and 08 hours.
You would think that this solves the issue, but not quite. It solves the issue if the process reaches the decision point until midnight. After midnight, you can’t add a whole new day and then another 08 hours.
So you should split your flow further to handle these two scenarios:
- Wait occurs prior to midnight => XPATH Expression interval = ‘P01DT08H’
- Wait occurs after midnight => XPATH Expression interval = ‘P00DT08H”
I’m pretty sure there are other ways to do it, but I decided to do it like this:
In which I set the XPATH for Time Date type of the other Timer (Red Light / After Midnight) as
So this should solve the case.
I added the project file for this:
Maverick (José Rodrigues)
Post Header image by Henrique Simplicio