How to trigger a gateway timer to trigger immediately but no more than four times per minute?

I usually use this construct at the top level of a script module:

from java.util.concurrent import LinkedBlockingDeque, TimeUnit

# Capacity = 100.  The new instance is thrown away if already in globals.
deque = system.util.getGlobals().setdefault('MySpecialForeverQueue', LinkedBlockingDeque(100))

def someTimerEvent(event):
	next = deque.poll(15000, TimeUnit.MILLISECONDS)
	if next:
		# handle it
# Run the above at a fixed **rate** matching the poll timeout.

Use ConcurrentLinkedDeque if you don't want any capacity. (It'll run a bit faster that a LinkedBlockingDeque that doesn't have a limit, IIRC.)

Queues are a bit faster than Deques, if you don't need bidirectional traffic.

6 Likes