summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-03-04 15:52:13 +0000
committerMike Buland <eichlan@xagasoft.com>2011-03-04 15:52:13 +0000
commit53202e5711f32c80ec89d149da7de72b2a1fc953 (patch)
treec7a8f688f718ae2643007e85ed1b035658461fd0
parent2cb55a3b17d2381c6ec61aea3cea077253ffab3c (diff)
downloadlibbu++-53202e5711f32c80ec89d149da7de72b2a1fc953.tar.gz
libbu++-53202e5711f32c80ec89d149da7de72b2a1fc953.tar.bz2
libbu++-53202e5711f32c80ec89d149da7de72b2a1fc953.tar.xz
libbu++-53202e5711f32c80ec89d149da7de72b2a1fc953.zip
Added some extra functions to Bu::MiniCron to let you execute jobs that are in
the queue immediately, with or without rescheduling, by id or name.
Diffstat (limited to '')
-rw-r--r--src/minicron.cpp57
-rw-r--r--src/minicron.h18
2 files changed, 72 insertions, 3 deletions
diff --git a/src/minicron.cpp b/src/minicron.cpp
index 3375492..95cf66b 100644
--- a/src/minicron.cpp
+++ b/src/minicron.cpp
@@ -119,6 +119,58 @@ void Bu::MiniCron::removeJob( JobId jid )
119 } 119 }
120} 120}
121 121
122void Bu::MiniCron::runJob( JobId jid, bool bReschedule )
123{
124 Bu::List<Job *> lJobs;
125 while( !hJobs.isEmpty() )
126 {
127 Job *pJob = hJobs.dequeue();
128 if( pJob->getId() == jid )
129 {
130 pJob->run( bReschedule );
131 if( !pJob->bContinue )
132 {
133 delete pJob;
134 break;
135 }
136 lJobs.append( pJob );
137 break;
138 }
139 lJobs.append( pJob );
140 }
141
142 for( Bu::List<Job *>::iterator i = lJobs.begin(); i; i++ )
143 {
144 hJobs.enqueue( *i );
145 }
146}
147
148void Bu::MiniCron::runJob( const Bu::String &sName, bool bReschedule )
149{
150 Bu::List<Job *> lJobs;
151 while( !hJobs.isEmpty() )
152 {
153 Job *pJob = hJobs.dequeue();
154 if( pJob->getName() == sName )
155 {
156 pJob->run( bReschedule );
157 if( !pJob->bContinue )
158 {
159 delete pJob;
160 break;
161 }
162 lJobs.append( pJob );
163 break;
164 }
165 lJobs.append( pJob );
166 }
167
168 for( Bu::List<Job *>::iterator i = lJobs.begin(); i; i++ )
169 {
170 hJobs.enqueue( *i );
171 }
172}
173
122Bu::MiniCron::JobInfoList Bu::MiniCron::getJobInfo() 174Bu::MiniCron::JobInfoList Bu::MiniCron::getJobInfo()
123{ 175{
124 JobInfoList lRet; 176 JobInfoList lRet;
@@ -148,10 +200,11 @@ Bu::MiniCron::Job::~Job()
148 pTimer = NULL; 200 pTimer = NULL;
149} 201}
150 202
151void Bu::MiniCron::Job::run() 203void Bu::MiniCron::Job::run( bool bReschedule )
152{ 204{
153 iRunCount++; 205 iRunCount++;
154 tNextRun = pTimer->nextTime(); 206 if( bReschedule )
207 tNextRun = pTimer->nextTime();
155 sigJob( *this ); 208 sigJob( *this );
156} 209}
157 210
diff --git a/src/minicron.h b/src/minicron.h
index 7ccf543..0d1cb62 100644
--- a/src/minicron.h
+++ b/src/minicron.h
@@ -110,6 +110,22 @@ namespace Bu
110 */ 110 */
111 virtual void removeJob( JobId jid ); 111 virtual void removeJob( JobId jid );
112 112
113 /**
114 * Executes the job specified right now. If bReschedule is true then
115 * the job is then removed from the queue and rescheduled as though
116 * it's time had come naturally to be run. Otherwise, it's run without
117 * interrupting the normal schedule.
118 */
119 virtual void runJob( JobId jid, bool bReschedule=false );
120
121 /**
122 * Executes the job specified right now. If bReschedule is true then
123 * the job is then removed from the queue and rescheduled as though
124 * it's time had come naturally to be run. Otherwise, it's run without
125 * interrupting the normal schedule.
126 */
127 virtual void runJob( const Bu::String &sName, bool bReschedule=false );
128
113 class JobInfo 129 class JobInfo
114 { 130 {
115 public: 131 public:
@@ -234,7 +250,7 @@ namespace Bu
234 * Execute this job once, increment the runcount and schedule the 250 * Execute this job once, increment the runcount and schedule the
235 * next occurance of it. 251 * next occurance of it.
236 */ 252 */
237 void run(); 253 void run( bool bReschedule=true );
238 254
239 /** 255 /**
240 * Get the time this job will next run. 256 * Get the time this job will next run.