python-scheduler icon indicating copy to clipboard operation
python-scheduler copied to clipboard

Easily run periodic tasks cron-style within your application.

Help on module scheduler:

NAME scheduler - Utilities to schedule and manage periodic events.

FILE /opt/projects/irrigation.todo/web/irrigation/irrigation/scheduler/scheduler.py

DESCRIPTION This module depends on dateutil, which is often not included in the base python packages installed in your system. Read here:

  http://labix.org/python-dateutil

for more details. Note that this library is extremely common. On Debian based
systems (including Ubuntu) you can install it with:

  apt-get install python-dateutil

CLASSES builtin.object RecurringEvent

class RecurringEvent(__builtin__.object)
 |  Creates a thread to periodically perform an action.
 |  
 |  You can use this object to periodically perform tasks within a python
 |  application. It does not require polling on file descriptor or having an
 |  event loop, each task is entirely independent.
 |  
 |  Relies on thread, it has been used within django application to easily manage
 |  periodic tasks. The main advantage over cron or system schedulers is that it
 |  is self contained in the application: you start it, you have your periodic
 |  tasks.  No need to fiddle with system files or to have extra installation
 |  steps.
 |  
 |  Note that this thread uses dateutil and rrules to compute exactly when the
 |  next event will need to run, and sleeps in between. It does not continuously
 |  poll like other implementations.
 |  
 |  Examples:
 |  
 |  Run CheckDatabase every monday at 2:20am
 |    RecurringEvent(
 |        "Update Database", OptimizeDatabase, RecurringEvent.WEEKLY,
 |        repetition={'byweekday': rrule.MO},
 |        time={'hour': 2, 'minutes': 20})
 |  
 |  Water plants every day at 08:00am:
 |    RecurringEvent("Water Plants", WaterPlants, RecurringEvent.DAILY,
 |                   time={'hour': 8, 'minutes': 00})
 |  
 |  Clean temporary files every minute at 15 seconds:
 |    RecurringEvent("Clean Temp files", self.CleanTempFiles,
 |                   RecurringEvent.MINUTELY, time={'seconds': 15})
 |  
 |  Methods defined here:
 |  
 |  Run(self)
 |      Sleeps and run events as requested.
 |  
 |  __init__(self, name, action, frequency, repetition={}, time={}, logger=None)
 |      Instantiates a RecurringEvent object.
 |      
 |      Args:
 |        name: string, name of the task, used for logging purposes only.
 |        action: lambda or generally function to invoke periodically.
 |        frequency: one of RecurringEvent.{YEARLY,MONTHLY,WEEKLY,DAILY,HOURLY,
 |          MINUTELY,SECONDLY}, to indicate when the event should repeat.
 |        repetition: dict, passed down as named arguments to the rrule
 |          constructor. This allows to set more esoteric repetitions.
 |          See examples, and http://labix.org/python-dateutil.
 |          Examples: RecurringEvent.MONTHLY, repetition={'bysetposition': -1}
 |          will run the event the last day of the month.
 |          RecurringEvent.YEARLY, repetition={'byeaster': 2} will run the event
 |          the second day after easter every year.
 |        time: dict, used to set a specific time to run the event at.
 |          Examples: RecurringEvent.DAILY, time={'hours': 8, 'minutes': 20}
 |          will run the event at 8:20 daily. RecurringEvent.MINUTELY,
 |          time={'seconds': 30} will run at every minute and 30 seconds.
 |          You can use repetition={...} to skip days or hours in cron style.
 |        logger: object implementing the logging interface, to log events.
 |          Generally you create the logger with logging.getLogger(...).
 |      
 |      Returns:
 |        Nothing. It will start running the event as requested, by spawning
 |        a separate thread.
 |      
 |      Notes:
 |        Times are always relative to your time zone. If you use this with
 |        django, don't forget to set the TIME_ZONE parameter in the settings
 |        file, otherwise you will get confused.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  DAILY = 3
 |  
 |  HOURLY = 4
 |  
 |  MAX_SLEEP_TIME = 600
 |  
 |  MINUTELY = 5
 |  
 |  MONTHLY = 1
 |  
 |  SECONDLY = 6
 |  
 |  WEEKLY = 2
 |  
 |  YEARLY = 0