# Gateway timer event fixed delay not correct

**URL:** <https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603>\
**Category:** Ignition\
**Created:** [September 11, 2020, 5:10pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603 "2020-09-11T17:10:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![deancable](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@deancable](https://forum.inductiveautomation.com/u/deancable)\
**Post date:** [September 11, 2020, 5:10pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/1 "2020-09-11T17:10:12Z")

</div>

Hello,

I used to use Ignition 7.9 and had gateway TIMER events defined as FIXED DELAY on DEDICATED threading to execute every 60 seconds.

The script within the timer event would take anywhere from 10-15 seconds to execute.  
THEN, 60 seconds after that the timer would execute again. Just like in the documentation.

However since I have upgraded to Ignition 8.0.13 this is not behaving the same.  
I have a “master” inheritable project defined.  
I have the gateway timer events defined in it.  
I have a “child” project defined that has my windows in it.

NOW when my gateway timer events fire, the execute as follows.

1. gateway starts.
2. 60 seconds later the timer fires.
3. My script within the timer executes for 10-15 seconds.  
(I verify this with logging.)
4. 50-45 seconds later the timer fires again!

What happened to the FIXED delay that used to be between the END of your script firing INSIDE the timer and the NEXT interval?

thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 11, 2020, 5:13pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/2 "2020-09-11T17:13:44Z")

</div>

> [@deancable](#):
>
> I have a “master” inheritable project defined.  
> I have the gateway timer events defined in it.

How many projects do you have inheriting this? Because that's how many copies of the script will be running. I suspect you are seeing logging from two different projects, not mistiming from one project. Gateway events should never be defined in an inheritable project, only in leaf projects.

---

<div class="post-metadata">

**Author:** ![deancable](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@deancable](https://forum.inductiveautomation.com/u/deancable)\
**Post date:** [September 11, 2020, 6:01pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/3 "2020-09-11T18:01:21Z")

</div>

Those are the only 2 PROJECTS in my gateway.  
“master” is inheritable.  
“child” is inherited from “master” and is not inheritable.

---

<div class="post-metadata">

**Author:** ![deancable](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@deancable](https://forum.inductiveautomation.com/u/deancable)\
**Post date:** [September 11, 2020, 6:07pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/4 "2020-09-11T18:07:17Z")

</div>

My gateway TIMER event is defined as follows:

60,000 ms  
Delay Type = FIXED DELAY  
Threading = DEDICATED

script:  
from time import sleep  
lSeconds = 10  
MES\_global.DB.logMessageDirectlyToDB(‘zTestFIXEDdelay’, 'Starting…sleeping for ’ + str(lSeconds))  
sleep(lSeconds)  
MES\_global.DB.logMessageDirectlyToDB(‘zTestFIXEDdelay’, ‘Finished’)

Since my script above takes 10 seconds to “run”.  
I would expect there to be 70 seconds between log entries that start with:  
'Starting…sleeping for 10

Here is the actual log entries:  
|2020-09-11 14:03:56.540|zTestFIXEDdelay|Starting…sleeping for 10|  
|2020-09-11 14:04:06.547|zTestFIXEDdelay|Finished|  
there should be a 60 second gap AFTER 14:04:06.547 above!!!  
|2020-09-11 14:04:56.537|zTestFIXEDdelay|Starting…sleeping for 10|  
|2020-09-11 14:05:06.543|zTestFIXEDdelay|Finished|  
|2020-09-11 14:05:56.550|zTestFIXEDdelay|Starting…sleeping for 10|

---

<div class="post-metadata">

**Author:** ![deancable](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@deancable](https://forum.inductiveautomation.com/u/deancable)\
**Post date:** [September 11, 2020, 6:19pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/5 "2020-09-11T18:19:09Z")

</div>

I changed the threading = SHARED.

same logging as above.  
from the END of one execution of the script, there is NOT 60 seconds before  
the next one begins.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 11, 2020, 6:23pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/6 "2020-09-11T18:23:31Z")

</div>

I’m able to replicate using this script:

```auto
from time import sleep

logger = system.util.getLogger('timer_test')

logger.info('starting')

sleep(10)

logger.info('finished')

```

with these settings:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/4/94d267e33f36fa17577af145f7fa43992bedf931.jpeg)

output:

```auto
I [timer_test] [18:21:13]: starting 
I [timer_test] [18:21:23]: finished 
I [timer_test] [18:22:13]: starting 
I [timer_test] [18:22:23]: finished 
I [timer_test] [18:23:13]: starting 
I [timer_test] [18:23:23]: finished 

```

---

<div class="post-metadata">

**Author:** ![deancable](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@deancable](https://forum.inductiveautomation.com/u/deancable)\
**Post date:** [September 11, 2020, 6:26pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/7 "2020-09-11T18:26:19Z")

</div>

Thanks Kevin.

Would you happen to have EASY access to an Ignition 7.9 you could check against?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 11, 2020, 6:53pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/8 "2020-09-11T18:53:32Z")

</div>

It doesn’t work as you’d expect in 7.9 either. It’s likely never work as expected.

The crazy thing is that this isn’t even some bug in Ignition (I mean technically it is because it’s not behaving like it should), but this is really either a bug in java.util.Timer or its documentation, because this is reproducible on its own in Java.

---

<div class="post-metadata">

**Author:** ![deancable](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@deancable](https://forum.inductiveautomation.com/u/deancable)\
**Post date:** [September 11, 2020, 8:27pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/9 "2020-09-11T20:27:08Z")

</div>

Can you suggest a workaround?

So that I get a 60,000ms delay AFTER my script executes…before it executes again?

---

<div class="post-metadata">

**Author:** ![deancable](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@deancable](https://forum.inductiveautomation.com/u/deancable)\
**Post date:** [September 21, 2020, 8:12pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/10 "2020-09-21T20:12:21Z")

</div>

Kevin Herron,

Will this be addressed in any upcoming versions?  
thank you

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 21, 2020, 8:34pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/11 "2020-09-21T20:34:10Z")

</div>

Hmm, it probably will be, there’s a ticket but it’s been marked low priority.

---

<div class="post-metadata">

**Author:** ![mori.luca](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mori.luca/32/13424_2.png) [@mori.luca](https://forum.inductiveautomation.com/u/mori.luca)\
**Post date:** [November 7, 2020, 12:14pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/12 "2020-11-07T12:14:52Z")

</div>

Hello everyone,  
i faced this same problem and i’d like to say that from my personal point of view,  
this shouldn’t be a low priority ticket.

Is there any news on this issue? The documentation is clear about fixed and delay interval.  
Is two months i’m struggling wit this, being thinking was something in my code.

Thanks for your time

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 7, 2020, 2:33pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/13 "2020-11-07T14:33:15Z")

</div>

I’ll note your objection and see if it can be re-reviewed.

Because these timers, while technically behaving incorrectly, have been behaving this way for over a decade and “fixing” them will alter the behavior of many existing projects, the fix may have serious repercussions.

---

<div class="post-metadata">

**Author:** ![BenKearney](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@BenKearney](https://forum.inductiveautomation.com/u/BenKearney)\
**Post date:** [November 7, 2020, 3:34pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/14 "2020-11-07T15:34:09Z")

</div>

I thought Java’s util.Timer fixed delay schedule implemented a fixed delay from the execution time (i.e. the time the task actually started), rather than from the time the task finished. Variance in how long the task took to execute shouldn’t change when the task is scheduled to run next.

To achieve what is described in the Ignition docs, I think the gateway script would need to manually call schedule() again after every execution for a single schedule rather than trying to set it up to run for an extended period with one call. I don’t know whether this would be fragile or not.

A workaround might be to bind a tag’s value to the system time and write an on change script that does something when the seconds == 0.

Edit: Hey I was reading that! 😆

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 7, 2020, 3:44pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/16 "2020-11-07T15:44:12Z")

</div>

> [@BenKearney](#):
>
> I thought Java’s util.Timer fixed delay schedule implemented a fixed delay from the execution time (i.e. the time the task actually started), rather than from the time the task finished.

Yes, that appears to be the case, but that is hardly distinguishable from fixed rate execution.

I ninja-deleted my original response because I misread yours. It was just a code sample showing that fixed delay execution with `java.util.Timer` is broken entirely independent of Ignition.

---

<div class="post-metadata">

**Author:** ![BenKearney](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@BenKearney](https://forum.inductiveautomation.com/u/BenKearney)\
**Post date:** [November 7, 2020, 3:47pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/17 "2020-11-07T15:47:27Z")

</div>

Yeah it's basically the same thing to an Ignition user. I think it still achieves one of the benefits from the Ignition docs:

> This is the safest option since it prevents a script from mistakenly running continuously because it takes longer to execute the script than the delay.

But this bit isn't accurate

> This means that the script's rate will actually be the delay plus the amount of time it takes to execute the script.

The difference probably isn't relevant to an Ignition user, but technically you did implement a fixed delay script - just defined it differently. Safest thing might be to add a third option and clarify what a fixed delay script is. Fixed Sleep or something similar.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 7, 2020, 3:48pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/18 "2020-11-07T15:48:58Z")

</div>

Fixed delay is defined and works as expected with `ScheduledExecutorService::scheduledWithFixedDelay`, which is what we’d probably use instead.

[https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/ScheduledExecutorService.html#scheduleWithFixedDelay(java.lang.Runnable,long,long,java.util.concurrent.TimeUnit)](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/ScheduledExecutorService.html#scheduleWithFixedDelay(java.lang.Runnable,long,long,java.util.concurrent.TimeUnit))

edit: I’m having a rough morning apparently.

---

<div class="post-metadata">

**Author:** ![BenKearney](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@BenKearney](https://forum.inductiveautomation.com/u/BenKearney)\
**Post date:** [November 7, 2020, 3:51pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/19 "2020-11-07T15:51:36Z")

</div>

Ah, the old “define fixed-delay two different ways in your documentation” trick. Java you rascal.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/2/82214d9aa264ad3a9d1c483050a5cd6c6d502c58.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/6/665107eb563f62b42e514cf9c7fcfb155323761e.png)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 7, 2020, 3:51pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/20 "2020-11-07T15:51:41Z")

</div>

Even the docs for `java.util.Timer` indicate it should behave how we want though:

> In fixed-delay execution, each execution is scheduled relative to the actual execution time of the previous execution.

[https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Timer.html#schedule(java.util.TimerTask,long,long)](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Timer.html#schedule(java.util.TimerTask,long,long))

How can you interpret that in a way that resembles fixed rate instead?

---

<div class="post-metadata">

**Author:** ![BenKearney](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@BenKearney](https://forum.inductiveautomation.com/u/BenKearney)\
**Post date:** [November 7, 2020, 3:52pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603/21 "2020-11-07T15:52:32Z")

</div>

> In fixed-delay execution, each execution is scheduled relative to the actual execution time of the previous execution.

Here they're using 'execution time' to mean the time that the function begins executing, not the time that it takes to execute. Bit ambiguous.

[Next page](https://forum.inductiveautomation.com/t/gateway-timer-event-fixed-delay-not-correct/38603.md?page=2)
