Wait extension
The wait extension pauses the workflow until a specified time.
Overview
A wait extension is code that can
be called directly from a workflow. It is implemented in the WaitExtension
class
in the com.ibm.itim.workflowextensions
package.
The following extension is provided:
scheduleTimeout
scheduleTimeout
Thepublic ProcessResult
scheduleTimeout(Date)
extension suspends the workflow until
the time specified by Date
, which is the standard
Date object in JavaScript.
When the specified time is reached, the extension activity is complete
and the workflow continues. Embed the wait extension in a loop in the workflow if you want the workflow to check a condition and continue only when the condition is no longer met. The loop requires the following logic:
- Check the condition.
- Calculate the target date for the wait extension from the current date. Use JavaScript.
- Run the wait extension. Use the calculated target date for
scheduleTimeout(Date)
.
For more information about Date
, see a JavaScript reference like
the following: JavaScript Date Reference.
Another possible reference is the ECMAScript(r) Language Specification, published
by ECMA International, which now administers the standards that are
the basis for JavaScript and
other scripting languages.
Examples
- A workflow loop checks CPU load and continues only when CPU load
falls below the desired level.
- Check CPU load.
- If CPU load is below the desired threshold: Exit the loop.
- If CPU load is above the desired threshold: Calculate the target
DATE
and then run the wait extension.
- When the wait extension is complete, loop to check CPU load again.
- Check CPU load.
- Enforce dynamically calculated timeouts for long-running workflow
activities. For example, implement an approval that is pending for two
working days.
- Calculate the target
DATE
. Use JavaScript. The calculation needs to account for workflows that are triggered near a weekend. For example, consider the desired period of two working days. If the workflow is triggered on a Friday, the target date is Tuesday (four elapsed days). If the workflow is triggered on a Monday, then the target date is Wednesday (two elapsed days). - Branch workflow execution that uses a fork type of
AND
. Put the approval on one branch and the wait extension with the targetDATE
on the other branch. - Merge the two branches with a join type of
OR
.
The workflow continues when either branch is complete: an approval is submitted or the wait extension times out.
- Calculate the target