Order of startup

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?

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:

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

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.
3 Likes

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?

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.

1 Like