From 53202e5711f32c80ec89d149da7de72b2a1fc953 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 4 Mar 2011 15:52:13 +0000 Subject: 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. --- src/minicron.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/minicron.h | 18 +++++++++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) (limited to 'src') 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 ) } } +void Bu::MiniCron::runJob( JobId jid, bool bReschedule ) +{ + Bu::List lJobs; + while( !hJobs.isEmpty() ) + { + Job *pJob = hJobs.dequeue(); + if( pJob->getId() == jid ) + { + pJob->run( bReschedule ); + if( !pJob->bContinue ) + { + delete pJob; + break; + } + lJobs.append( pJob ); + break; + } + lJobs.append( pJob ); + } + + for( Bu::List::iterator i = lJobs.begin(); i; i++ ) + { + hJobs.enqueue( *i ); + } +} + +void Bu::MiniCron::runJob( const Bu::String &sName, bool bReschedule ) +{ + Bu::List lJobs; + while( !hJobs.isEmpty() ) + { + Job *pJob = hJobs.dequeue(); + if( pJob->getName() == sName ) + { + pJob->run( bReschedule ); + if( !pJob->bContinue ) + { + delete pJob; + break; + } + lJobs.append( pJob ); + break; + } + lJobs.append( pJob ); + } + + for( Bu::List::iterator i = lJobs.begin(); i; i++ ) + { + hJobs.enqueue( *i ); + } +} + Bu::MiniCron::JobInfoList Bu::MiniCron::getJobInfo() { JobInfoList lRet; @@ -148,10 +200,11 @@ Bu::MiniCron::Job::~Job() pTimer = NULL; } -void Bu::MiniCron::Job::run() +void Bu::MiniCron::Job::run( bool bReschedule ) { iRunCount++; - tNextRun = pTimer->nextTime(); + if( bReschedule ) + tNextRun = pTimer->nextTime(); sigJob( *this ); } 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 */ virtual void removeJob( JobId jid ); + /** + * Executes the job specified right now. If bReschedule is true then + * the job is then removed from the queue and rescheduled as though + * it's time had come naturally to be run. Otherwise, it's run without + * interrupting the normal schedule. + */ + virtual void runJob( JobId jid, bool bReschedule=false ); + + /** + * Executes the job specified right now. If bReschedule is true then + * the job is then removed from the queue and rescheduled as though + * it's time had come naturally to be run. Otherwise, it's run without + * interrupting the normal schedule. + */ + virtual void runJob( const Bu::String &sName, bool bReschedule=false ); + class JobInfo { public: @@ -234,7 +250,7 @@ namespace Bu * Execute this job once, increment the runcount and schedule the * next occurance of it. */ - void run(); + void run( bool bReschedule=true ); /** * Get the time this job will next run. -- cgit v1.2.3