Creating a BasicExecutionEngine schedule

I’m trying to use the BasicExecutionEngine to create a tasks schedule, but I’m having issues (doesn’t help my Java knowledge is lacking).
@pturmel (Does Ignition have schedule events?)

from java.lang import Runnable
from com.inductiveautomation.ignition.common.execution.impl import BasicExecutionEngine

class Task(Runnable):
	def run(self):
		print 'Hellooo'

s = BasicExecutionEngine()
s.schedule("task", Task, "0-59 * * * *")

I’m receiving the error:

Traceback (most recent call last):
  File "<buffer>", line 9, in <module>
TypeError: schedule(): 2nd arg can't be coerced to java.lang.Runnable

Python usage error. You are providing your Task class when you need to provide a Task instance. Your last line should look like this:

s.schedule("task", Task(), "0-59 * * * *")

By the way, you can put an asterisk in the minute column, too.....

Cheers, I thought it was going to be something silly like that :slight_smile:

Looks like it’s working now, thanks!

If I put this code in the gateway startup script, I assume that it will run on the gateway?

Also, how would I get a reference to my BasicExecutionEngine object from another script? (I setup the schedule in my Script Console and not sure how to stop it… Also would be useful to know!)

So, object persistence is the kind of thing that can eat your lunch. I would use system.util.getGlobals() to maintain a true single instance, with code to shutdown any prior instance upon script restart. Something like this:

MyBEE = BasicExecutionEngine()
_g = system.util.getGlobals()
_oldBEE = _g.get('some_unique_key_for_BEE')
_g['some_unique_key_for_BEE'] = MyBEE
if _oldBEE:
    _oldBEE.shutdown()

Elsewhere, you can use project.someScript.MyBEE to access the engine. I think you keep the string returned from .schedule() to use with .unSchedule().

1 Like