API Reference¶
-
pyramid_cron.
add_cron_task
(config, f, min='*', hour='*', day='*', month='*', dow='*')[source]¶ Register a function for execution by the scheduler.
Task functions must have the following signature:
def mytask(system): request = system['request'] registry = system['registry'] # do stuff
Additional keys may be added in the future: the single-arg signature ensures that task functions will be forward-compatible.
In addition to the callback function, you can specify a schedule, using a cron-like syntax. For the time periods of
min
,hour
,day
,month
, anddow
(day of week), you can specify an integer, a set of integers, or the ‘*’ wildcard character. The default argument is ‘*’. Hours are specified in 24-hour time.For example, this will run the task every day, at 2:00:
config.add_cron_task(..., hour=2)
This will run the task every day at 2:00, 10:00, and 18:00:
config.add_cron_task(..., hour=[2, 10, 18])
To run the task ‘every 2 hours’, you can use
range()
:config.add_cron_task(..., hour=range(0, 24, 2))
Parameters: - f – The function to execute. Task functions must have accept a single
argument, which will be a
system
dict containing keys for the Pyramidrequest
andregistry
. - min – Specify which minutes to run the task.
- hour – Specify which hours to run the task.
- day – Specify which days to run the task.
- month – Specify which months to run the task.
- dow – Specify which days of the week to run the task.
- f – The function to execute. Task functions must have accept a single
argument, which will be a