cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Timer calls timer subscription randomly or multiple times at once

JK_10744682
8-Gravel

Timer calls timer subscription randomly or multiple times at once

Hi all,

 

I found a weird bug that I wanted to bring up. I created a timer that calls every 5 minutes. It does some calculations and sets a few property values. I was making some changes to it, and it started calling the timer subscription randomly or several times at once rather than every 5 minutes as expected. I tried to debug and ended up duplicating the timer and deleting the original one and it now works perfectly fine after making a new one with the exact same services/subscriptions. Any ideas why this would happen? It seemed very strange.

2 REPLIES 2

Hi @JK_10744682 ,

Be warned, this is best-guess based on the information provided.

 

The timer basically triggers the subscription code at the desired interval.

It does not enforce that the event will happen at the expected time - what it does is that it will add that code to be executed in a queue. If either the calculation takes longer than the interval it's being triggered, or the CPU is overloaded, it will definitely not trigger as you would expect it.

I'm guessing when changing the CRON you might have set it to a faster interval, which triggered many Tick events, which then executed as fast as they could be (which would be serially).

You can test this with a Timer that executes each second, but you put inside a service with a pause (or something else that takes 5 seconds, a loop etc) and put some start and end logger statements to see in the Script Log when exactly they are executed.

 

 

The Timer fires directly after it was started, and then continues calling based on set interval. This is somewhat unexpected and one needs to be aware of.

 

I assume you did maybe make changes in code or other changes on the Timer and saved the entity (multiple) times. Each save will fire the timer (as the entity restarts on save). May this be an explanation?

Announcements


Top Tags