$types = JobQueueGroup::singleton()->getDefaultQueueTypes();
}
+ // Handle any required periodic queue maintenance
+ $this->executeReadyPeriodicTasks();
+
$memcKey = 'jobqueue:dbs:v3';
$pendingDbInfo = $wgMemc->get( $memcKey );
$pendingDBs = array(); // (job type => (db list))
foreach ( $wgLocalDatabases as $db ) {
- $types = JobQueueGroup::singleton( $db )->getQueuesWithJobs();
- foreach ( $types as $type ) {
+ foreach ( JobQueueGroup::singleton( $db )->getQueuesWithJobs() as $type ) {
$pendingDBs[$type][] = $db;
}
}
return $pendingDBs;
}
+
+ /**
+ * Do all ready periodic jobs for all databases every 5 minutes (and .1% of the time)
+ * @return integer
+ */
+ private function executeReadyPeriodicTasks() {
+ global $wgLocalDatabases, $wgMemc;
+
+ $count = 0;
+ $memcKey = 'jobqueue:periodic:lasttime';
+ $timestamp = (int)$wgMemc->get( $memcKey ); // UNIX timestamp or 0
+ if ( ( time() - $timestamp ) > 300 || mt_rand( 0, 999 ) == 0 ) { // 5 minutes
+ if ( $wgMemc->add( "$memcKey:rebuild", 1, 1800 ) ) { // lock
+ foreach ( $wgLocalDatabases as $db ) {
+ $count += JobQueueGroup::singleton( $db )->executeReadyPeriodicTasks();
+ }
+ $wgMemc->set( $memcKey, time() );
+ $wgMemc->delete( "$memcKey:rebuild" ); // unlock
+ }
+ }
+
+ return $count;
+ }
}
$maintClass = "nextJobDb";