SQL tag timing solutions

Looking for possible solutions for a timing issue I am having.

memory tags - SQL parameters for SQL tag

SQL tag - grabs data at fixed rate from DB1 (results are constantly changing but query parameters are constant unless changed by trigger event)

Data tags - couple simple expression tags reformat some of that data from the SQL tag with data from other ignition tags

DB ref tags - couple of memory tags that get updated with references that gateway timer script uses to enter data into DB2

gateway timer script - grabs data at a high rate from Data tags and inserts into DB2 based on the DB ref tags

Trigger event - from operator input changes the memory tags so the SQL tag has new parameters and sets new values for the DB ref tags.

My issue appears to be in the timing that one the trigger event occurs the timer script can trigger after the DB ref tags are updated by the trigger event but before the SQL tag refreshes so that I end up with results from old SQL tag data into DB2 so I need to make sure that after a trigger event occurs that the gateway timer script doesn't run till after the SQL tag does an update.

what I have done is made
(A) Memory tag DateTime - set by tag change script on the SQL tag
(B) Memory tag DateTime - set by tag change script on DB ref tags
(C) Expression tag - if time A > time B

then set timer script to not run unless (C) is true

I think this should work and testing now but wondering if I am making this harder then it should / could be. Other solutions?

I never use SQL query tags. Timing is just too unpredictable. I would do everything in a project library script that is called from a timer event. Every time it is called, it would check the trigger tags of interest and return early if there is nothing to do. Otherwise, it would gather all necessary data, run the query, post-process, and write all result tags (in that order). All in the one script.

A timer event cannot overrun, so there is no possibility of race conditions.

1 Like