State machine in Gateway

We are monitoring a process running in the machine. There is a Gateway Scheduled event that triggers the start. After that, we have a function that has to do some checks until this other process finishes. The period at which these checks are run is not critical as long as they are fast enough.

In a client what I would do is to call the same check in an invoke later function with a delay until no further calls are needed.

Is there a way to do that elegantly in the gateway? A system timer or be able to enable or disable programatically a Scheduled event?

Right now we run a scheduled event every minute all the time, but 90% of the time it does nothing, just checks that the secondary process is idle and exits.

Just use a timer event. The first thing the event would do is read the tags for the current state. If idle, return early. Treat your jython as a substitute for ladder logic (or structure text), running like a PLC task on an interval. Set the timer interval to meet your latency requirements for the process.