TIMER_30SEC event

Based on my limited observations, it appears that the TIMER_30SEC event fires on the 25s and 55s marks. I would like to schedule an action every 5 minutes, on the 5 minute (00:05, 00:10, 00:15, etc). Therefore, would the following approach be a reliable method for determining that my action should run?

let msNow = Math.floor(getTimestamp()/1000) + 5;

// TIMER_30SEC appears to fire 5 seconds prior to the 30s and 60s marks, 
// so let's add 5 to convert:
let eventEpochSecs = msNow + 5; 
debug("Time: "+eventEpochSecs+" Mod60: "+(eventEpochSecs%60));

// Now, let's check to see if we're executing on the 5 minute mark using a molulo of 5 minutes:
if( (eventEpochSecs%(60*5)) == 0 ){
   debug("Five minute mark!");
}

image

As you can see from the output, the above code block appears to work consistently in my lab. A couple questions:

  1. I presume this event executes 5 seconds prior to the 30/60 mark so that any metrics that are committed during this event are immediately processed by the subsequent METRIC_COMMIT cycle. Is that correct?
  2. Is the 5 second assumption above correct, and therefore I can rely on this event always executing on the 25s and 55s marks?

Currently, we make no guarantee about precisely when TIMER_30SEC fires. There is no relationship between the 30 second interval it uses and wall clock seconds. If the capture is restarted, you will likely see a different interval in the debug log. I don’t think it would be unreasonable, or a breaking change, for us to add such a guarantee as an enhancement, but for now, it’s incorrect to assume the event will fire at the 25/55 second marks.

I use the following code to fire the TIME_30 event on a specific interval (modified for the 5 minute interval you’re looking for)

let now = getTimestamp();
if((now % 300000) >= 30000){
    // this should only be false once every five minutes
    return;
}

// insert code you want to run once every 5 minutes here.
2 Likes