FIFO Buffer / Queue


I'm triggering a gateway script when a TCP last receive time is updated. A string is brought in, parsed, and assigned to a memory tag. I now need to create a FIFO buffer (at gateway level) that the strings can queue into and out of. Unfortunately, it doesn't look like any typical python commands for FIFO are available in Ignition.
Can anyone make some recommendations of how create this FIFO buffer/queue system for strings?
Within the string, I have a bit that specifies if it is an 'add' or 'cancel' request. that will be used to determine if the string is coming in or out of the buffer.

Any help or suggestions are greatly appreciated. Thank you!

I use database tables for most of my data structures like fifo/lifo etc as they are then preserved in case of gateway or client restarts.

I like that idea a lot. Do you have any examples you could share of how your are moving that information around? -Pushing/Pulling from database, incrementing queue, ect.

I tend to use a java.util.concurrent.LinkedBlockingQueue (or corresponding Deque) for such applications. If you are careful to only put native python objects into it, it is safe to make a long-lived instance in system.util.getGlobals() or a similar persistent dictionary from my LifeCycle module.

You can push into these Queues (use the .offer() method) with very low latency from anywhere (they are thread-safe), and drain them in bulk in a gateway timer event. I consider this a best practice to avoid long-lived background threads.

1 Like

Just the normal SQL commands of insert/select/delete. Insert to put a new node in, delete to pop it, select to peek, and update if you need to change the order around.