Cron

A cron lets you schedule a job to be created periodically. Time and dates are specified using the standard crontab format. Crons can be triggered as often as every minute, and there’s no limit to the number of crons you register.

Register

The interfaces for registering a cron are similar to creating a job in Python with cloud.call and creating a job in the shell with picloud exec. There are two additional parameters needed:

  • Label: A name for the new cron that will be used when referencing the cron in the future.
  • Schedule: Schedule is a BSD-style cron timestamp, specified as 5 values delimited by spaces. The ordering of the characters represent scheduling information for minutes, hours, days, months, and days of week. See the full format specification. Year is not supported.

Example in Python:

>>> cloud.cron.register(f, 'mylabel', '* * * * *') # runs every minute

Example in the Shell:

$ picloud cron register mylabel '* * * * *' command.

List

To see all registered crons, in Python:

>>> cloud.cron.list()
[u'mylabel']

In the shell:

$ picloud cron list
label
mylabel

Query Info

We let you query information about a cron you’ve previously registered.

Info Description
core_type The core type of the jobs that the cron creates.
created When the cron was first registered.
creator_host The hostname of the machine that registered the cron.
func_name Name of the function or command that was registered.
last_jid The Job Id of the last job created by the cron.
last_run The last time a job was created by the cron.
schedule The schedule you specified on registration.

In Python:

>>> cloud.cron.info('mylabel')
{u'core_type': u'c1',
 u'created': u'2012-11-20 01:14:44',
 u'creator_host': u'picloud-demo-machine',
 u'func_name': u'__main__.hi at <ipython-input-1-103d693f48e6>:1',
 u'label': u'test',
 u'last_jid': 42,
 u'last_run': u'2012-11-01 01:21:10',
 u'schedule': u'* * * * *'}

In the Shell:

$ picloud cron info mylabel

Manually Run

Manually triggering a cron off of its schedule makes testing easier.

In Python:

>>> cloud.cron.manual_run('mylabel')

In the shell:

$ picloud cron run mylabel

Deregister

Use deregister to disable and remove a cron.

In Python:

>>> cloud.cron.deregister('mylabel')

In the shell:

$ picloud cron deregister mylabel