summaryrefslogtreecommitdiff
path: root/src/minicron.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-01-15 18:30:31 +0000
committerMike Buland <eichlan@xagasoft.com>2010-01-15 18:30:31 +0000
commit42f921e3dad53405f67463f57eefd52b095ee11f (patch)
tree78c8c0308ee5867fa9359a679daa0680a8d62995 /src/minicron.h
parent5471d34089277ad5c622fd9c392b9270229d9e3d (diff)
downloadlibbu++-42f921e3dad53405f67463f57eefd52b095ee11f.tar.gz
libbu++-42f921e3dad53405f67463f57eefd52b095ee11f.tar.bz2
libbu++-42f921e3dad53405f67463f57eefd52b095ee11f.tar.xz
libbu++-42f921e3dad53405f67463f57eefd52b095ee11f.zip
Documented more of MiniCron, and added some cool new help features to OptParser.
Diffstat (limited to 'src/minicron.h')
-rw-r--r--src/minicron.h52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/minicron.h b/src/minicron.h
index b100ad0..3e6beea 100644
--- a/src/minicron.h
+++ b/src/minicron.h
@@ -30,6 +30,12 @@ namespace Bu
30 * By default a job will continually reschedule itself after being run 30 * By default a job will continually reschedule itself after being run
31 * unless it calls stop() on it's job object, it is removed using 31 * unless it calls stop() on it's job object, it is removed using
32 * removeJob() on the cron object, or it is added with addJobOnce. 32 * removeJob() on the cron object, or it is added with addJobOnce.
33 *
34 *@todo A minor change to the job execution system could allow a Timer to
35 * defer or reschedule execution instead of the job executing. This would,
36 * in effect, allow us to do every type of interesting scheduling that
37 * systems like fcron offer, including time constrained load-balanced
38 * execution.
33 */ 39 */
34 class MiniCron 40 class MiniCron
35 { 41 {
@@ -89,16 +95,35 @@ namespace Bu
89 */ 95 */
90 virtual void removeJob( JobId jid ); 96 virtual void removeJob( JobId jid );
91 97
98 /**
99 * The baseclass for timer/schedulers for MiniCron jobs. Classes that
100 * inherit from this are used to determine when jobs will run and at
101 * what interval.
102 */
92 class Timer 103 class Timer
93 { 104 {
94 public: 105 public:
95 Timer(); 106 Timer();
96 virtual ~Timer(); 107 virtual ~Timer();
97 108
109 /**
110 * Called by MiniCron when each job is run to determine the next
111 * time that a job should be run. When a job is run, this function
112 * is actually called before the job is executed again so that the
113 * job can tell when the next time it will be run will be.
114 */
98 virtual time_t nextTime()=0; 115 virtual time_t nextTime()=0;
116
117 /**
118 * This function should return a copy of the child class.
119 */
99 virtual Timer *clone() const = 0; 120 virtual Timer *clone() const = 0;
100 }; 121 };
101 122
123 /**
124 * Execute the job every tInterval seconds, also you can delay the
125 * first run by a different amount of time from the job's creation.
126 */
102 class TimerInterval : public Timer 127 class TimerInterval : public Timer
103 { 128 {
104 public: 129 public:
@@ -113,6 +138,23 @@ namespace Bu
113 time_t tInterval; 138 time_t tInterval;
114 }; 139 };
115 140
141 /**
142 * A much more general timer class that can be used for much more
143 * "cron-like" functionality. The constructor takes a string that
144 * describes the times that the job should be run. At the moment the
145 * following schemes are understood:
146 *
147 * "daily [hour] [minute]"
148 * "hourly [minute]"
149 * "weekly [day] [hour] [minute]"
150 *
151 * In these examples each word in [brackets] represents a number that
152 * matches the data type in the brackets. [day] is the number of days
153 * since sunday, 0-6. You can also use lowercase three character
154 * abbreviations for the day names.
155 *
156 * Many more forms follow.
157 */
116 class TimerBasic : public Timer 158 class TimerBasic : public Timer
117 { 159 {
118 public: 160 public:
@@ -142,13 +184,21 @@ namespace Bu
142 Bu::FString sSpec; 184 Bu::FString sSpec;
143 }; 185 };
144 186
187 /**
188 * Represents a MiniCron Job. This class is used for both internal
189 * job management as well as job slot interaction and control. Objects
190 * of this class are passed into the slots that are signaled when a job
191 * is executed.
192 */
145 class Job 193 class Job
146 { 194 {
147 friend class Bu::MiniCron; 195 friend class Bu::MiniCron;
148 public: 196 private:
149 Job( JobId jid, bool bRepeat=true ); 197 Job( JobId jid, bool bRepeat=true );
150 virtual ~Job(); 198 virtual ~Job();
151 199
200 public:
201
152 /** 202 /**
153 * Execute this job once, increment the runcount and schedule the 203 * Execute this job once, increment the runcount and schedule the
154 * next occurance of it. 204 * next occurance of it.