Package gavo :: Package base :: Module cron
[frames] | no frames]

Module cron

source code

A cron-like facility to regularly run some functions.

Most of the apparatus in here is not really for user consumption. There's a singleton of the queue created below, and the methods of that singleton are exposed as module-level functions.

To make the jobs actually execute, the running program has to call registerSchedulerFunction(schedulerFunction). Only the first registration is relevant. The schedulerFunction has the signature sf(delay, callable) and has to arrange for callable to be called delay seconds in the future; twisted's reactor.callLater works like this.

However, you should arrange for previous callLaters to be canceled when a new one comes in. There is no management to make sure only one queue reaper runs at any time (it doesn't hurt much if more than one run, but it's a waste of resources).

Classes
  AbstractJob
A job run in a queue.
  IntervalJob
A job that's executed roughly every interval seconds.
  TimedJob
A job that's run roughly daily at some wallclock (UTC) times.
  Queue
A cron-job queue.
Functions
 
sendMailToAdmin(subject, message)
tries to send a mail to the configured administrator.
source code
 
runEvery(seconds, name, callable)
schedules callable to be run every seconds.
source code
 
repeatAt(times, name, callable)
schedules callable to be run every day at times.
source code
 
registerScheduleFunction(scheduleFunction) source code
 
clearScheduleFunction() source code
Variables
  __package__ = 'gavo.base'
Function Details

sendMailToAdmin(subject, message)

source code 

tries to send a mail to the configured administrator.

This relies on a functional mail infrastructure on the local host.

runEvery(seconds, name, callable)

source code 

schedules callable to be run every seconds.

name must be a unique identifier for the "job". jobs with identical names overwrite each other.

callable will be run in the main thread, so it must finish quickly or it will block the server.

repeatAt(times, name, callable)

source code 

schedules callable to be run every day at times.

times is a list of (day-of-month, day-of-week, hour, minute) tuples. day-of-month and/or day-of-week are 1-based and may be None (if both are non-none, day-of-week wins).

name must be a unique identifier for the "job". jobs with identical names overwrite each other.

callable will be run in the main thread, so it must finish quickly or it will block the server.