Getting the current timer from context

Hey guys (and girls, or both?!), 

A while back I was trying to figure out how to get the current timer that is running from context and after a long search I finally found it.

First a little bit of information on the actually initiation of timers by Outsystems:

The scheduler service that's running calls a certain page to iniate timers, it sends XML data to this page.
This XML contains some information on the timer to be run, which also includes the SSKey of the timer.

So now that you know that, you can get the current running timer by doing the following:

1) Use the GetRequestContent action from HTTPRequestHandler ( you can set IncludeHeaders to false)

2) Add a Regex_Search from the Text extension, as an input set GetRequestContent.RawContent and for the Pattern use the following: 

"(?<=<ssKey>)(.*?)(?=</ssKey>)"

You can keep the other inputs empty here.

3) Regex_Search.PatternResult will contain the SSKey of the current running timer.

4) Almost there! We can Query the Meta_Cyclic_Job entity to find our TimerId by filtering on Meta_Cyclic_Job.SS_Key = Regex_Search.PatternResult.

5) Now you have the Meta_Cyclic_Job entry for this timer! This entity contains the timeout, effective timeout, Espace_Id, name and a few more attributes.

6) With the Meta_Cyclic_Job.Id you can get extra information on the Cyclic_Job entity, which contains information on the timer itself, wether it's running or not, the duration, who initated it and more!

7) If you wish to get log data for this timer you can find this in the Log_Cyclic_Job entity, however you again need to use the SSKey to find these, for some reason the Meta_Cyclic_Job.Id is not being used here. These logs also contain Error_Id, which can be found in the Log_Error entity to provide some more information if an error was logged.


So to summise:

Use GetRequestContent and Regex_Search actions to get the current SS_Key to get the current running timer from the Meta_Cyclic_Job entity.

Meta_Cyclic_Job entity, contains generic information on the timer (describes the timer).

Cyclic_Job entity, contains the schedule and running of the timer (last, next run, duration, current runtime.

Log_Cyclic_Job entity, contains the information on each run of the timer and also wether there was an error or not.

Log_Error entity, contains the error information.


In addition to this post I made an idea: https://www.outsystems.com/ideas/6930/more-runtime-information-on-timers

It would be so much easier if Outsystems would provide us with some information on the timer at runtime instead of us having to go around it in such a way to just get the current running timer.
If the scheduler service ever changes this might become obsolete and a different method will have to be found. It might be possible that multiple timers are running and you wish to prevent this (multiple front end servers or multiple tenants might cause the same timer to run at the same time ?) or you want to keep track of the timeout and prevent a timer from reaching the time out (huge batches of data needing to be processed might cause a timeout and you would like to have a proper way of handling those batches without causing a timeout).

Thank you for sharing your findings Joey. It's always interesting to read about the internals of the platform. 

I've been involved in a project that required coordination between different Timers and what we did was orchestrate their execution through one master Timer. I wasn't aware that you could obtain Timer data from within your own Timer like this.

Solution

Afonso Carvalho wrote:

Thank you for sharing your findings Joey. It's always interesting to read about the internals of the platform. 

I've been involved in a project that required coordination between different Timers and what we did was orchestrate their execution through one master Timer. I wasn't aware that you could obtain Timer data from within your own Timer like this.


Hey Afonso,

That's exactly why I looked into this in the first place.
I also created a component for this to allow other devs to implement this.
Though you need to add an action to all timers, I haven't found a way to use a callback on the timer scheduler or something. (which brings me to my next idea https://www.outsystems.com/ideas/6933/callback-action-before-starting-timer-and-after-completing-timer )

https://www.outsystems.com/forge/component-overview/5363/timerwait

Solution