Javadoc link

The Cron service is a thin wrapper of the Cron4J project.  The purpose is to provide a scheduling service which can send any message to any other service at a predetermined interval.  It will provide scheduling for MyRobotLab's auto-update feature.  Some other applications include turning lights, sprinklers, coffee machines, or other appliances on or off at regular intervals.

 

A thin service wrapper for the most excellent Cron4J project.

References:

Example code (from branch develop):
#file : Cron.py (github)
# The following script will send a quote to a Log and Python every minute
from datetime import datetime
 
cron  =  runtime.start('cron', 'Cron')
log   =  runtime.start('log', 'Log')
speech = runtime.start("speech","MarySpeech")
 
# add a task which sends text to the log service Log.log(string) every minute
cron.addTask('* * * * *','log','log', 'hello sir, time for your coffee')
# add a task to send text to a python function every minute
cron.addTask('* * * * *','python','doThisEveryMinute', 'hello sir, time for your coffee')
 
print ('now is', datetime.now())
 
def doThisEveryMinute(text):
  print (datetime.now())
  print (datetime.time(datetime.now()),text)
  speech.speak(text)
 
listOfTasks = cron.getCronTasks()
for i in listOfTasks:
  print(i.name, i.cronPattern, i.method)

Alessandruino

11 years 7 months ago

 

Here is the corrected python script
 
speech = Runtime.create("speech","Speech")
speech.startService()
cron   =  Runtime.createAndStart("cron", "Cron")
log   =  Runtime.createAndStart("log", "Log")
cron.addScheduledEvent("* * * * *","log","log", "hello sir, time for your coffee")
cron.addScheduledEvent("* * * * *","speech","speak", "hello sir, time for your coffee")

Hi

I seems like the Cron service has changed since the sample script was created.

 I changed the syntax to match the current verison of Cron

 

speech = Runtime.create("speech","AcapelaSpeech")
speech.startService()
cron =  Runtime.create("cron", "Cron")
cron.startService()
log = Runtime.createAndStart("log", "Log")
cron.addTask("* * * * *","log","log", "hello sir, time for your coffee")
cron.addTask("* * * * *","speech","speak", "hello sir, time for your coffee")
 
 
Example configuration (from branch develop):
#file : Cron.py (github)
!!org.myrobotlab.service.config.ServiceConfig
listeners: null
peers: null
type: Cron