-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
122 lines (112 loc) · 4.82 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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