Cron

javadoc

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:

Examples:


#file : service/Cron.py edit raw
# The following script will send a quote to a Log and Python every minute
from datetime import datetime

cron  =  Runtime.createAndStart('cron', 'Cron')
log   =  Runtime.createAndStart('log', 'Log')
speech = Runtime.createAndStart("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')

dateObj = datetime
print dateObj.now()

def doThisEveryMinute(text):
  print dateObj.now()
  print dateObj.time(dateObj.now()),text
  speech.speak(text)

listOfTasks = cron.getCronTasks()
for i in listOfTasks:
  print(i.name, i.cronPattern, i.method)

Alessandruino's picture

  Here is the corrected

 

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")
GroG's picture

Thanks Alessandruino

Thanks Alessandruino !

Corrected...

Mats's picture

Updated py script

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")