# Order of startup

**URL:** <https://forum.inductiveautomation.com/t/order-of-startup/99732>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 12, 2024, 6:07am UTC](https://forum.inductiveautomation.com/t/order-of-startup/99732 "2024-12-12T06:07:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 12, 2024, 6:07am UTC](https://forum.inductiveautomation.com/t/order-of-startup/99732/1 "2024-12-12T06:07:25Z")

</div>

I'm often tripped up by startup events which expect certain other things to be already initialised by the time they run, however oftentimes they're not, such as the tagging system when trying to execute code on gateway startup (for example, trying to call `system.tag.read*` within a script library root will be unable to read the tags on gateway startup when the library is first initialised).

Is there a resource which defines the startup order of things in various scopes?

- Gateway startup
- Perspective Session startup

And, for a specific question, is the tag system initialised and running by the time a Gateway Startup event is fired?

---

<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:** [December 12, 2024, 1:23pm UTC](https://forum.inductiveautomation.com/t/order-of-startup/99732/2 "2024-12-12T13:23:10Z")

</div>

No documentation of order. Tags start up in parallel with everything else. Avoid reading tags or doing any network callouts in the top level of project scripts anyways:

> [@\[IGN-6503\]Project Library Script Initialization Races](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636):
>
> Are you annoyed by pseudo-random breakage in Ignition project library scripting? Odd top-level constants being garbled, or operations in the top level that have side effects running twice? Or more? Not happening much, but always around project edits, and sometimes even on gateway restart? Yeah, me too. frowning_face Poking around under the hood back in the spring, for a module development task, I ran across some problematic IA bytecode and pinged some people. But it went nowhere, as I co…

I would expect tags to be initialized **after** scripting anyways, because they generate script operations.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 12, 2024, 4:11pm UTC](https://forum.inductiveautomation.com/t/order-of-startup/99732/3 "2024-12-12T16:11:39Z")

</div>

> [@nminchin](#):
>
> Is there a resource which defines the startup order of things in various scopes?

This would be close to impossible to do:

1. It would be locking our implementation details to a particular contract
2. Startup order of things like Perspective sessions is intentionally not explicit w.r.t. the platform, because the set of modules you have installed is going to vary, which could shape your dependency graph, which will affect your startup order. The less special cases we have in our codebase, the better.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 12, 2024, 9:13pm UTC](https://forum.inductiveautomation.com/t/order-of-startup/99732/4 "2024-12-12T21:13:37Z")

</div>

What's the best way to run a library function that initialises a library variable which needs to read (memory) tag values, on startup, in gateway scope?

---

<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:** [December 12, 2024, 10:07pm UTC](https://forum.inductiveautomation.com/t/order-of-startup/99732/5 "2024-12-12T22:07:31Z")

</div>

If you look at my Tag Report Utility project from the Exchange, you will find that it performs a tag query operation to initialize a cache of tag folders per tag provider. That obviously has to delay until the tags exist, so it monitors the gateway's own internal status and defers the startup function until it is RUNNING, plus some additional delay.
