Calculating a time interval
You can use ESQL to calculate the time interval between two events, and to set a timer to be triggered after a specified interval.
About this task
(When you make a call to a CURRENT_ datetime function, the value that is returned is identical to the value returned to another call in the same node. This ensures that you can use the function consistently within a single node.)
CALL CopyMessageHeaders();
Declare PutTime INTERVAL;
SET PutTime = (CURRENT_GMTTIME - InputRoot.MQMD.PutTime) MINUTE TO SECOND;
SET OutputRoot.XMLNS.Test.PutTime = PutTime;
The output message has the format (although actual values vary):
<Test>
<PutTime>INTERVAL '1:21.862' MINUTE TO SECOND</PutTime>
</Test>
Example
The following code snippet sets a timer, to be triggered after a specified interval from the start of processing, in order to check that processing has completed. If processing has not completed within the elapsed time, the firing of the timer might, for example, trigger some recovery processing.
The StartTime
field
of the timeout request message is set to the current time plus the
allowed delay period, which is defined by a user-defined property
on the flow. (The user-defined property has been set to a string of
the form "HH:MM:SS" by the administrator.)
DECLARE StartDelyIntervalStr EXTERNAL CHARACTER '01:15:05';
CREATE PROCEDURE ValidateTimeoutRequest() BEGIN
-- Set the timeout period
DECLARE timeoutStartTimeRef REFERENCE TO
OutputRoot.XMLNSC.Envelope.Header.TimeoutRequest.StartTime;
IF LASTMOVE(timeoutStartTimeRef)
THEN
-- Already set
ELSE
-- Set it from the UDP StartDelyIntervalStr
DECLARE startAtTime TIME CURRENT_TIME
+ CAST(StartDelyIntervalStr AS INTERVAL HOUR TO SECOND);
-- Convert "TIME 'hh.mm.ss.fff'" to hh.mm.ss format
-- needed in StartTime field
DECLARE startAtTimeStr CHAR;
SET startAtTimeStr = startAtTime;
SET startAtTimeStr = SUBSTRING(startAtTimeStr FROM 7 FOR 8);
SET OutputRoot.XMLNSC.Envelope.Header.TimeoutRequest.StartTime
= startAtTimeStr;
END IF;
END;