From: Siebrand Mazeland Date: Mon, 25 Nov 2013 14:38:37 +0000 (+0100) Subject: Update formatting of job related files X-Git-Tag: 1.31.0-rc.0~17907^2 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=52e945aff8f45ca3e7f9ef8f7411df2e42b072a9;p=lhc%2Fweb%2Fwiklou.git Update formatting of job related files Change-Id: I634c26061f0ac1231647a9062b6cea01b77136bd --- diff --git a/includes/job/Job.php b/includes/job/Job.php index ab7df5d2ed..0359540109 100644 --- a/includes/job/Job.php +++ b/includes/job/Job.php @@ -70,6 +70,7 @@ abstract class Job { global $wgJobClasses; if ( isset( $wgJobClasses[$command] ) ) { $class = $wgJobClasses[$command]; + return new $class( $title, $params, $id ); } throw new MWException( "Invalid job command `{$command}`" ); @@ -225,6 +226,7 @@ abstract class Job { // Likewise for jobs with different delay times unset( $info['params']['jobReleaseTimestamp'] ); } + return $info; } @@ -305,6 +307,7 @@ abstract class Job { if ( $paramString !== '' ) { $s .= ' ' . $paramString; } + return $s; } else { return "{$this->command} $paramString"; diff --git a/includes/job/JobQueue.php b/includes/job/JobQueue.php index 6556ee85c7..b8a612cc08 100644 --- a/includes/job/JobQueue.php +++ b/includes/job/JobQueue.php @@ -106,6 +106,7 @@ abstract class JobQueue { if ( !( $obj instanceof self ) ) { throw new MWException( "Class '$class' is not a " . __CLASS__ . " class." ); } + return $obj; } @@ -177,6 +178,7 @@ abstract class JobQueue { wfProfileIn( __METHOD__ ); $res = $this->doIsEmpty(); wfProfileOut( __METHOD__ ); + return $res; } @@ -199,6 +201,7 @@ abstract class JobQueue { wfProfileIn( __METHOD__ ); $res = $this->doGetSize(); wfProfileOut( __METHOD__ ); + return $res; } @@ -221,6 +224,7 @@ abstract class JobQueue { wfProfileIn( __METHOD__ ); $res = $this->doGetAcquiredCount(); wfProfileOut( __METHOD__ ); + return $res; } @@ -244,6 +248,7 @@ abstract class JobQueue { wfProfileIn( __METHOD__ ); $res = $this->doGetDelayedCount(); wfProfileOut( __METHOD__ ); + return $res; } @@ -268,6 +273,7 @@ abstract class JobQueue { wfProfileIn( __METHOD__ ); $res = $this->doGetAbandonedCount(); wfProfileOut( __METHOD__ ); + return $res; } @@ -321,6 +327,7 @@ abstract class JobQueue { wfProfileIn( __METHOD__ ); $ok = $this->doBatchPush( $jobs, $flags ); wfProfileOut( __METHOD__ ); + return $ok; } @@ -358,7 +365,9 @@ abstract class JobQueue { JobQueue::incrStats( 'job-pop-duplicate', $this->type ); $job = DuplicateJob::newFromJob( $job ); // convert to a no-op } - } catch ( MWException $e ) {} // don't lose jobs over this + } catch ( MWException $e ) { + // don't lose jobs over this + } return $job; } @@ -386,6 +395,7 @@ abstract class JobQueue { wfProfileIn( __METHOD__ ); $ok = $this->doAck( $job ); wfProfileOut( __METHOD__ ); + return $ok; } @@ -433,6 +443,7 @@ abstract class JobQueue { wfProfileIn( __METHOD__ ); $ok = $this->doDeduplicateRootJob( $job ); wfProfileOut( __METHOD__ ); + return $ok; } @@ -476,6 +487,7 @@ abstract class JobQueue { wfProfileIn( __METHOD__ ); $isDuplicate = $this->doIsRootJobOldDuplicate( $job ); wfProfileOut( __METHOD__ ); + return $isDuplicate; } @@ -504,6 +516,7 @@ abstract class JobQueue { */ protected function getRootJobCacheKey( $signature ) { list( $db, $prefix ) = wfSplitWikiID( $this->wiki ); + return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, 'rootjob', $signature ); } @@ -518,6 +531,7 @@ abstract class JobQueue { wfProfileIn( __METHOD__ ); $res = $this->doDelete(); wfProfileOut( __METHOD__ ); + return $res; } @@ -547,7 +561,8 @@ abstract class JobQueue { * @see JobQueue::waitForBackups() * @return void */ - protected function doWaitForBackups() {} + protected function doWaitForBackups() { + } /** * Return a map of task names to task definition maps. @@ -566,6 +581,7 @@ abstract class JobQueue { foreach ( $tasks as $name => &$def ) { $def['name'] = $name; } + return $tasks; } @@ -592,7 +608,8 @@ abstract class JobQueue { * @see JobQueue::flushCaches() * @return void */ - protected function doFlushCaches() {} + protected function doFlushCaches() { + } /** * Get an iterator to traverse over all available jobs in this queue. @@ -637,6 +654,7 @@ abstract class JobQueue { */ final public function getSiblingQueuesWithJobs( array $types ) { $section = new ProfileSection( __METHOD__ ); + return $this->doGetSiblingQueuesWithJobs( $types ); } @@ -661,6 +679,7 @@ abstract class JobQueue { */ final public function getSiblingQueueSizes( array $types ) { $section = new ProfileSection( __METHOD__ ); + return $this->doGetSiblingQueueSizes( $types ); } @@ -702,5 +721,8 @@ abstract class JobQueue { * @ingroup JobQueue * @since 1.22 */ -class JobQueueError extends MWException {} -class JobQueueConnectionError extends JobQueueError {} +class JobQueueError extends MWException { +} + +class JobQueueConnectionError extends JobQueueError { +} diff --git a/includes/job/JobQueueDB.php b/includes/job/JobQueueDB.php index c39083df16..59d3de160c 100644 --- a/includes/job/JobQueueDB.php +++ b/includes/job/JobQueueDB.php @@ -198,7 +198,7 @@ class JobQueueDB extends JobQueue { $that = $this; $method = __METHOD__; $dbw->onTransactionIdle( - function() use ( $dbw, $that, $jobs, $flags, $method ) { + function () use ( $dbw, $that, $jobs, $flags, $method ) { $that->doBatchPushInternal( $dbw, $jobs, $flags, $method ); } ); @@ -289,7 +289,7 @@ class JobQueueDB extends JobQueue { $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction $autoTrx = $dbw->getFlag( DBO_TRX ); // get current setting $dbw->clearFlag( DBO_TRX ); // make each query its own transaction - $scopedReset = new ScopedCallback( function() use ( $dbw, $autoTrx ) { + $scopedReset = new ScopedCallback( function () use ( $dbw, $autoTrx ) { $dbw->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore old setting } ); @@ -485,7 +485,7 @@ class JobQueueDB extends JobQueue { $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction $autoTrx = $dbw->getFlag( DBO_TRX ); // get current setting $dbw->clearFlag( DBO_TRX ); // make each query its own transaction - $scopedReset = new ScopedCallback( function() use ( $dbw, $autoTrx ) { + $scopedReset = new ScopedCallback( function () use ( $dbw, $autoTrx ) { $dbw->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore old setting } ); @@ -520,7 +520,7 @@ class JobQueueDB extends JobQueue { // jobs to become no-ops without any actual jobs that made them redundant. $dbw = $this->getMasterDB(); $cache = $this->dupCache; - $dbw->onTransactionIdle( function() use ( $cache, $params, $key, $dbw ) { + $dbw->onTransactionIdle( function () use ( $cache, $params, $key, $dbw ) { $timestamp = $cache->get( $key ); // current last timestamp of this job if ( $timestamp && $timestamp >= $params['rootJobTimestamp'] ) { return true; // a newer version of this root job was enqueued @@ -544,6 +544,7 @@ class JobQueueDB extends JobQueue { } catch ( DBError $e ) { $this->throwDBException( $e ); } + return true; } @@ -586,7 +587,7 @@ class JobQueueDB extends JobQueue { return new MappedIterator( $dbr->select( 'job', '*', array( 'job_cmd' => $this->getType(), 'job_token' => '' ) ), - function( $row ) use ( $dbr ) { + function ( $row ) use ( $dbr ) { $job = Job::factory( $row->job_cmd, Title::makeTitle( $row->job_namespace, $row->job_title ), @@ -618,6 +619,7 @@ class JobQueueDB extends JobQueue { foreach ( $res as $row ) { $types[] = $row->job_cmd; } + return $types; } @@ -630,6 +632,7 @@ class JobQueueDB extends JobQueue { foreach ( $res as $row ) { $sizes[$row->job_cmd] = (int)$row->count; } + return $sizes; } @@ -663,7 +666,7 @@ class JobQueueDB extends JobQueue { __METHOD__ ); $ids = array_map( - function( $o ) { + function ( $o ) { return $o->job_id; }, iterator_to_array( $res ) ); @@ -699,7 +702,7 @@ class JobQueueDB extends JobQueue { // the IDs first means that the UPDATE can be done by primary key (less deadlocks). $res = $dbw->select( 'job', 'job_id', $conds, __METHOD__ ); $ids = array_map( - function( $o ) { + function ( $o ) { return $o->job_id; }, iterator_to_array( $res ) ); @@ -723,20 +726,21 @@ class JobQueueDB extends JobQueue { */ protected function insertFields( Job $job ) { $dbw = $this->getMasterDB(); + return array( // Fields that describe the nature of the job - 'job_cmd' => $job->getType(), + 'job_cmd' => $job->getType(), 'job_namespace' => $job->getTitle()->getNamespace(), - 'job_title' => $job->getTitle()->getDBkey(), - 'job_params' => self::makeBlob( $job->getParams() ), + 'job_title' => $job->getTitle()->getDBkey(), + 'job_params' => self::makeBlob( $job->getParams() ), // Additional job metadata - 'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ), + 'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ), 'job_timestamp' => $dbw->timestamp(), - 'job_sha1' => wfBaseConvert( + 'job_sha1' => wfBaseConvert( sha1( serialize( $job->getDeduplicationInfo() ) ), 16, 36, 31 ), - 'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM ) + 'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM ) ); } @@ -770,6 +774,7 @@ class JobQueueDB extends JobQueue { $lb = ( $this->cluster !== false ) ? wfGetLBFactory()->getExternalLB( $this->cluster, $this->wiki ) : wfGetLB( $this->wiki ); + return $lb->getConnectionRef( $index, array(), $this->wiki ); } @@ -779,6 +784,7 @@ class JobQueueDB extends JobQueue { private function getCacheKey( $property ) { list( $db, $prefix ) = wfSplitWikiID( $this->wiki ); $cluster = is_string( $this->cluster ) ? $this->cluster : 'main'; + return wfForeignMemcKey( $db, $prefix, 'jobqueue', $cluster, $this->type, $property ); } diff --git a/includes/job/JobQueueFederated.php b/includes/job/JobQueueFederated.php index 36f4959ecd..f598d29ad0 100644 --- a/includes/job/JobQueueFederated.php +++ b/includes/job/JobQueueFederated.php @@ -49,14 +49,17 @@ class JobQueueFederated extends JobQueue { /** @var Array (partition name => weight) reverse sorted by weight */ protected $partitionMap = array(); + /** @var Array (partition name => JobQueue) reverse sorted by weight */ protected $partitionQueues = array(); + /** @var HashRing */ protected $partitionPushRing; + /** @var BagOStuff */ protected $cache; - protected $maxPartitionsTry; // integer; maximum number of partitions to try + protected $maxPartitionsTry; // integer; maximum number of partitions to try const CACHE_TTL_SHORT = 30; // integer; seconds to cache info without re-validating const CACHE_TTL_LONG = 300; // integer; seconds to cache info that is kept up to date @@ -104,8 +107,8 @@ class JobQueueFederated extends JobQueue { // Get the config to pass to merge into each partition queue config $baseConfig = $params; foreach ( array( 'class', 'sectionsByWiki', 'maxPartitionsTry', - 'partitionsBySection', 'configByPartition', 'partitionsNoPush' ) as $o ) - { + 'partitionsBySection', 'configByPartition', 'partitionsNoPush' ) as $o + ) { unset( $baseConfig[$o] ); // partition queue doesn't care about this } // Get the partition queue objects @@ -149,6 +152,7 @@ class JobQueueFederated extends JobQueue { try { if ( !$queue->doIsEmpty() ) { $this->cache->add( $key, 'false', self::CACHE_TTL_LONG ); + return false; } } catch ( JobQueueError $e ) { @@ -157,6 +161,7 @@ class JobQueueFederated extends JobQueue { } $this->cache->add( $key, 'true', self::CACHE_TTL_LONG ); + return true; } @@ -199,6 +204,7 @@ class JobQueueFederated extends JobQueue { } $this->cache->set( $key, $count, self::CACHE_TTL_SHORT ); + return $count; } @@ -215,6 +221,7 @@ class JobQueueFederated extends JobQueue { throw new JobQueueError( "Could not insert job(s), {$this->maxPartitionsTry} partitions tried." ); } + return true; } @@ -318,6 +325,7 @@ class JobQueueFederated extends JobQueue { } if ( $job ) { $job->metadata['QueuePartition'] = $partition; + return $job; } else { unset( $partitionsTry[$partition] ); // blacklist partition @@ -325,6 +333,7 @@ class JobQueueFederated extends JobQueue { } $this->cache->set( $key, 'true', JobQueueDB::CACHE_TTL_LONG ); + return false; } @@ -332,6 +341,7 @@ class JobQueueFederated extends JobQueue { if ( !isset( $job->metadata['QueuePartition'] ) ) { throw new MWException( "The given job has no defined partition name." ); } + return $this->partitionQueues[$job->metadata['QueuePartition']]->ack( $job ); } @@ -345,6 +355,7 @@ class JobQueueFederated extends JobQueue { return $this->partitionQueues[$partitions[1]]->doIsRootJobOldDuplicate( $job ); } } + return false; } @@ -358,6 +369,7 @@ class JobQueueFederated extends JobQueue { return $this->partitionQueues[$partitions[1]]->doDeduplicateRootJob( $job ); } } + return false; } @@ -388,6 +400,7 @@ class JobQueueFederated extends JobQueue { $tasks["{$partition}:{$task}"] = $def; } } + return $tasks; } @@ -412,6 +425,7 @@ class JobQueueFederated extends JobQueue { foreach ( $this->partitionQueues as $queue ) { $iterator->append( $queue->getAllQueuedJobs() ); } + return $iterator; } @@ -420,6 +434,7 @@ class JobQueueFederated extends JobQueue { foreach ( $this->partitionQueues as $queue ) { $iterator->append( $queue->getAllDelayedJobs() ); } + return $iterator; } @@ -445,6 +460,7 @@ class JobQueueFederated extends JobQueue { MWExceptionHandler::logException( $e ); } } + return array_values( $result ); } @@ -464,6 +480,7 @@ class JobQueueFederated extends JobQueue { MWExceptionHandler::logException( $e ); } } + return $result; } @@ -478,6 +495,7 @@ class JobQueueFederated extends JobQueue { */ private function getCacheKey( $property ) { list( $db, $prefix ) = wfSplitWikiID( $this->wiki ); + return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, $property ); } } diff --git a/includes/job/JobQueueGroup.php b/includes/job/JobQueueGroup.php index fa7fee5faf..70820d5a58 100644 --- a/includes/job/JobQueueGroup.php +++ b/includes/job/JobQueueGroup.php @@ -66,6 +66,7 @@ class JobQueueGroup { if ( !isset( self::$instances[$wiki] ) ) { self::$instances[$wiki] = new self( $wiki ); } + return self::$instances[$wiki]; } @@ -157,6 +158,7 @@ class JobQueueGroup { if ( !$job ) { JobQueueAggregator::singleton()->notifyQueueEmpty( $this->wiki, $qtype ); } + return $job; } else { // any job in the "default" jobs types if ( $flags & self::USE_CACHE ) { @@ -269,6 +271,7 @@ class JobQueueGroup { } } } + return $types; } @@ -289,6 +292,7 @@ class JobQueueGroup { } } } + return $sizeMap; } @@ -339,8 +343,10 @@ class JobQueueGroup { // later jobs have not been done yet. This helps throttle queue spam. $deprioritized = !$this->get( 'refreshLinks' )->isEmpty(); $this->cache->set( 'isDeprioritized', $type, $deprioritized ); + return $deprioritized; } + return false; } @@ -368,8 +374,8 @@ class JobQueueGroup { if ( $definition['period'] <= 0 ) { continue; // disabled } elseif ( !isset( $lastRuns[$type][$task] ) - || $lastRuns[$type][$task] < ( time() - $definition['period'] ) ) - { + || $lastRuns[$type][$task] < ( time() - $definition['period'] ) + ) { try { if ( call_user_func( $definition['callback'] ) !== null ) { $tasksRun[$type][$task] = time(); @@ -382,13 +388,13 @@ class JobQueueGroup { } } - $wgMemc->merge( $key, function( $cache, $key, $lastRuns ) use ( $tasksRun ) { + $wgMemc->merge( $key, function ( $cache, $key, $lastRuns ) use ( $tasksRun ) { if ( is_array( $lastRuns ) ) { foreach ( $tasksRun as $type => $tasks ) { foreach ( $tasks as $task => $timestamp ) { if ( !isset( $lastRuns[$type][$task] ) - || $timestamp > $lastRuns[$type][$task] ) - { + || $timestamp > $lastRuns[$type][$task] + ) { $lastRuns[$type][$task] = $timestamp; } } @@ -396,6 +402,7 @@ class JobQueueGroup { } else { $lastRuns = $tasksRun; } + return $lastRuns; } ); @@ -420,6 +427,7 @@ class JobQueueGroup { } else { $value = $wgConf->getConfig( $this->wiki, $name ); $wgMemc->set( $key, array( 'v' => $value ), 86400 + mt_rand( 0, 86400 ) ); + return $value; } } diff --git a/includes/job/JobQueueRedis.php b/includes/job/JobQueueRedis.php index 67bb5a41ed..3bed28e382 100644 --- a/includes/job/JobQueueRedis.php +++ b/includes/job/JobQueueRedis.php @@ -134,6 +134,7 @@ class JobQueueRedis extends JobQueue { $conn->multi( Redis::PIPELINE ); $conn->zSize( $this->getQueueKey( 'z-claimed' ) ); $conn->zSize( $this->getQueueKey( 'z-abandoned' ) ); + return array_sum( $conn->exec() ); } catch ( RedisException $e ) { $this->throwRedisException( $this->server, $conn, $e ); @@ -217,6 +218,7 @@ class JobQueueRedis extends JobQueue { } if ( $failed > 0 ) { wfDebugLog( 'JobQueueRedis', "Could not insert {$failed} {$this->type} job(s)." ); + return false; } JobQueue::incrStats( 'job-insert', $this->type, count( $items ) ); @@ -428,12 +430,14 @@ LUA; if ( !$res ) { wfDebugLog( 'JobQueueRedis', "Could not acknowledge {$this->type} job." ); + return false; } } catch ( RedisException $e ) { $this->throwRedisException( $this->server, $conn, $e ); } } + return true; } @@ -457,6 +461,7 @@ LUA; if ( $timestamp && $timestamp >= $params['rootJobTimestamp'] ) { return true; // a newer version of this root job was enqueued } + // Update the timestamp of the last root job started at the location... return $conn->set( $key, $params['rootJobTimestamp'], self::ROOTJOB_TTL ); // 2 weeks } catch ( RedisException $e ) { @@ -501,6 +506,7 @@ LUA; foreach ( $props as $prop ) { $keys[] = $this->getQueueKey( $prop ); } + return ( $conn->delete( $keys ) !== false ); } catch ( RedisException $e ) { $this->throwRedisException( $this->server, $conn, $e ); @@ -515,12 +521,15 @@ LUA; $conn = $this->getConnection(); try { $that = $this; + return new MappedIterator( $conn->lRange( $this->getQueueKey( 'l-unclaimed' ), 0, -1 ), - function( $uid ) use ( $that, $conn ) { + function ( $uid ) use ( $that, $conn ) { return $that->getJobFromUidInternal( $uid, $conn ); }, - array( 'accept' => function ( $job ) { return is_object( $job ); } ) + array( 'accept' => function ( $job ) { + return is_object( $job ); + } ) ); } catch ( RedisException $e ) { $this->throwRedisException( $this->server, $conn, $e ); @@ -535,12 +544,15 @@ LUA; $conn = $this->getConnection(); try { $that = $this; + return new MappedIterator( // delayed jobs $conn->zRange( $this->getQueueKey( 'z-delayed' ), 0, -1 ), - function( $uid ) use ( $that, $conn ) { + function ( $uid ) use ( $that, $conn ) { return $that->getJobFromUidInternal( $uid, $conn ); }, - array( 'accept' => function ( $job ) { return is_object( $job ); } ) + array( 'accept' => function ( $job ) { + return is_object( $job ); + } ) ); } catch ( RedisException $e ) { $this->throwRedisException( $this->server, $conn, $e ); @@ -573,6 +585,7 @@ LUA; } catch ( RedisException $e ) { $this->throwRedisException( $this->server, $conn, $e ); } + return $sizes; } @@ -597,6 +610,7 @@ LUA; $title = Title::makeTitle( $item['namespace'], $item['title'] ); $job = Job::factory( $item['type'], $title, $item['params'] ); $job->metadata['uuid'] = $item['uuid']; + return $job; } catch ( RedisException $e ) { $this->throwRedisException( $this->server, $conn, $e ); @@ -734,6 +748,7 @@ LUA; 'period' => 300 // 5 minutes ); } + return $tasks; } @@ -744,18 +759,18 @@ LUA; protected function getNewJobFields( Job $job ) { return array( // Fields that describe the nature of the job - 'type' => $job->getType(), - 'namespace' => $job->getTitle()->getNamespace(), - 'title' => $job->getTitle()->getDBkey(), - 'params' => $job->getParams(), + 'type' => $job->getType(), + 'namespace' => $job->getTitle()->getNamespace(), + 'title' => $job->getTitle()->getDBkey(), + 'params' => $job->getParams(), // Some jobs cannot run until a "release timestamp" - 'rtimestamp' => $job->getReleaseTimestamp() ?: 0, + 'rtimestamp' => $job->getReleaseTimestamp() ? : 0, // Additional job metadata - 'uuid' => UIDGenerator::newRawUUIDv4( UIDGenerator::QUICK_RAND ), - 'sha1' => $job->ignoreDuplicates() - ? wfBaseConvert( sha1( serialize( $job->getDeduplicationInfo() ) ), 16, 36, 31 ) - : '', - 'timestamp' => time() // UNIX timestamp + 'uuid' => UIDGenerator::newRawUUIDv4( UIDGenerator::QUICK_RAND ), + 'sha1' => $job->ignoreDuplicates() + ? wfBaseConvert( sha1( serialize( $job->getDeduplicationInfo() ) ), 16, 36, 31 ) + : '', + 'timestamp' => time() // UNIX timestamp ); } @@ -768,8 +783,10 @@ LUA; if ( $title ) { $job = Job::factory( $fields['type'], $title, $fields['params'] ); $job->metadata['uuid'] = $fields['uuid']; + return $job; } + return false; } @@ -780,10 +797,12 @@ LUA; protected function serialize( array $fields ) { $blob = serialize( $fields ); if ( $this->compression === 'gzip' - && strlen( $blob ) >= 1024 && function_exists( 'gzdeflate' ) ) - { + && strlen( $blob ) >= 1024 + && function_exists( 'gzdeflate' ) + ) { $object = (object)array( 'blob' => gzdeflate( $blob ), 'enc' => 'gzip' ); $blobz = serialize( $object ); + return ( strlen( $blobz ) < strlen( $blob ) ) ? $blobz : $blob; } else { return $blob; @@ -803,6 +822,7 @@ LUA; $fields = false; } } + return is_array( $fields ) ? $fields : false; } @@ -817,6 +837,7 @@ LUA; if ( !$conn ) { throw new JobQueueConnectionError( "Unable to connect to redis server." ); } + return $conn; } diff --git a/includes/job/aggregator/JobQueueAggregator.php b/includes/job/aggregator/JobQueueAggregator.php index a8186abd4d..142b162cd6 100644 --- a/includes/job/aggregator/JobQueueAggregator.php +++ b/includes/job/aggregator/JobQueueAggregator.php @@ -34,7 +34,8 @@ abstract class JobQueueAggregator { /** * @param array $params */ - protected function __construct( array $params ) {} + protected function __construct( array $params ) { + } /** * @return JobQueueAggregator @@ -74,6 +75,7 @@ abstract class JobQueueAggregator { wfProfileIn( __METHOD__ ); $ok = $this->doNotifyQueueEmpty( $wiki, $type ); wfProfileOut( __METHOD__ ); + return $ok; } @@ -93,6 +95,7 @@ abstract class JobQueueAggregator { wfProfileIn( __METHOD__ ); $ok = $this->doNotifyQueueNonEmpty( $wiki, $type ); wfProfileOut( __METHOD__ ); + return $ok; } @@ -110,6 +113,7 @@ abstract class JobQueueAggregator { wfProfileIn( __METHOD__ ); $res = $this->doGetAllReadyWikiQueues(); wfProfileOut( __METHOD__ ); + return $res; } @@ -127,6 +131,7 @@ abstract class JobQueueAggregator { wfProfileIn( __METHOD__ ); $res = $this->doPurge(); wfProfileOut( __METHOD__ ); + return $res; } diff --git a/includes/job/aggregator/JobQueueAggregatorMemc.php b/includes/job/aggregator/JobQueueAggregatorMemc.php index 9434da0459..d733a422c7 100644 --- a/includes/job/aggregator/JobQueueAggregatorMemc.php +++ b/includes/job/aggregator/JobQueueAggregatorMemc.php @@ -65,6 +65,7 @@ class JobQueueAggregatorMemc extends JobQueueAggregator { } $this->cache->delete( "$key:lock" ); // unlock } + return true; } @@ -103,6 +104,7 @@ class JobQueueAggregatorMemc extends JobQueueAggregator { $this->cache->delete( "$key:rebuild" ); // unlock } } + return is_array( $pendingDbInfo ) ? $pendingDbInfo['pendingDBs'] : array(); // cache is both empty and locked diff --git a/includes/job/aggregator/JobQueueAggregatorRedis.php b/includes/job/aggregator/JobQueueAggregatorRedis.php index f1922a32ad..ca8975af6e 100644 --- a/includes/job/aggregator/JobQueueAggregatorRedis.php +++ b/includes/job/aggregator/JobQueueAggregatorRedis.php @@ -60,9 +60,11 @@ class JobQueueAggregatorRedis extends JobQueueAggregator { } try { $conn->hDel( $this->getReadyQueueKey(), $this->encQueueName( $type, $wiki ) ); + return true; } catch ( RedisException $e ) { $this->handleException( $conn, $e ); + return false; } } @@ -74,9 +76,11 @@ class JobQueueAggregatorRedis extends JobQueueAggregator { } try { $conn->hSet( $this->getReadyQueueKey(), $this->encQueueName( $type, $wiki ), time() ); + return true; } catch ( RedisException $e ) { $this->handleException( $conn, $e ); + return false; } } @@ -124,6 +128,7 @@ class JobQueueAggregatorRedis extends JobQueueAggregator { return $pendingDBs; } catch ( RedisException $e ) { $this->handleException( $conn, $e ); + return array(); } } @@ -137,8 +142,10 @@ class JobQueueAggregatorRedis extends JobQueueAggregator { $conn->delete( $this->getReadyQueueKey() ); } catch ( RedisException $e ) { $this->handleException( $conn, $e ); + return false; } + return true; } @@ -156,6 +163,7 @@ class JobQueueAggregatorRedis extends JobQueueAggregator { break; } } + return $conn; } @@ -190,6 +198,7 @@ class JobQueueAggregatorRedis extends JobQueueAggregator { */ private function dencQueueName( $name ) { list( $type, $wiki ) = explode( '/', $name, 2 ); + return array( rawurldecode( $type ), rawurldecode( $wiki ) ); } } diff --git a/includes/job/jobs/AssembleUploadChunksJob.php b/includes/job/jobs/AssembleUploadChunksJob.php index 6237e568a4..fb5fb58507 100644 --- a/includes/job/jobs/AssembleUploadChunksJob.php +++ b/includes/job/jobs/AssembleUploadChunksJob.php @@ -39,6 +39,7 @@ class AssembleUploadChunksJob extends Job { $user = $context->getUser(); if ( !$user->isLoggedIn() ) { $this->setLastError( "Could not load the author user from session." ); + return false; } @@ -48,6 +49,7 @@ class AssembleUploadChunksJob extends Job { // the user does not necessarily mean the session was loaded. // Most likely cause by suhosin.session.encrypt = On. $this->setLastError( "Error associating with user session. Try setting suhosin.session.encrypt = Off" ); + return false; } @@ -71,6 +73,7 @@ class AssembleUploadChunksJob extends Job { array( 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status ) ); $this->setLastError( $status->getWikiText() ); + return false; } @@ -108,8 +111,10 @@ class AssembleUploadChunksJob extends Job { ) ); $this->setLastError( get_class( $e ) . ": " . $e->getText() ); + return false; } + return true; } @@ -118,6 +123,7 @@ class AssembleUploadChunksJob extends Job { if ( is_array( $info['params'] ) ) { $info['params'] = array( 'filekey' => $info['params']['filekey'] ); } + return $info; } diff --git a/includes/job/jobs/DoubleRedirectJob.php b/includes/job/jobs/DoubleRedirectJob.php index 33e749b8fb..991b2eb716 100644 --- a/includes/job/jobs/DoubleRedirectJob.php +++ b/includes/job/jobs/DoubleRedirectJob.php @@ -85,18 +85,21 @@ class DoubleRedirectJob extends Job { function run() { if ( !$this->redirTitle ) { $this->setLastError( 'Invalid title' ); + return false; } $targetRev = Revision::newFromTitle( $this->title, false, Revision::READ_LATEST ); if ( !$targetRev ) { wfDebug( __METHOD__ . ": target redirect already deleted, ignoring\n" ); + return true; } $content = $targetRev->getContent(); $currentDest = $content ? $content->getRedirectTarget() : null; if ( !$currentDest || !$currentDest->equals( $this->redirTitle ) ) { wfDebug( __METHOD__ . ": Redirect has changed since the job was queued\n" ); + return true; } @@ -104,6 +107,7 @@ class DoubleRedirectJob extends Job { $mw = MagicWord::get( 'staticredirect' ); if ( $content->matchMagicWord( $mw ) ) { wfDebug( __METHOD__ . ": skipping: suppressed with __STATICREDIRECT__\n" ); + return true; } @@ -111,6 +115,7 @@ class DoubleRedirectJob extends Job { $newTitle = self::getFinalDestination( $this->redirTitle ); if ( !$newTitle ) { wfDebug( __METHOD__ . ": skipping: single redirect, circular redirect or invalid redirect destination\n" ); + return true; } if ( $newTitle->equals( $this->redirTitle ) ) { @@ -128,12 +133,14 @@ class DoubleRedirectJob extends Job { if ( $newContent->equals( $content ) ) { $this->setLastError( 'Content unchanged???' ); + return false; } $user = $this->getUser(); if ( !$user ) { $this->setLastError( 'Invalid user' ); + return false; } @@ -171,6 +178,7 @@ class DoubleRedirectJob extends Job { $titleText = $title->getPrefixedDBkey(); if ( isset( $seenTitles[$titleText] ) ) { wfDebug( __METHOD__, "Circular redirect detected, aborting\n" ); + return false; } $seenTitles[$titleText] = true; @@ -198,6 +206,7 @@ class DoubleRedirectJob extends Job { $dest = $title = Title::makeTitle( $row->rd_namespace, $row->rd_title, '', $row->rd_interwiki ); } } + return $dest; } @@ -216,6 +225,7 @@ class DoubleRedirectJob extends Job { self::$user->addToDatabase(); } } + return self::$user; } } diff --git a/includes/job/jobs/DuplicateJob.php b/includes/job/jobs/DuplicateJob.php index be1bfe5c81..b3f337114f 100644 --- a/includes/job/jobs/DuplicateJob.php +++ b/includes/job/jobs/DuplicateJob.php @@ -50,6 +50,7 @@ final class DuplicateJob extends Job { $djob->params = is_array( $djob->params ) ? $djob->params : array(); $djob->params = array( 'isDuplicate' => true ) + $djob->params; $djob->metadata = $job->metadata; + return $djob; } diff --git a/includes/job/jobs/EmaillingJob.php b/includes/job/jobs/EmaillingJob.php index 9fbf31244c..f24cebb622 100644 --- a/includes/job/jobs/EmaillingJob.php +++ b/includes/job/jobs/EmaillingJob.php @@ -43,5 +43,4 @@ class EmaillingJob extends Job { return $status->isOK(); } - } diff --git a/includes/job/jobs/EnotifNotifyJob.php b/includes/job/jobs/EnotifNotifyJob.php index bbe988d04b..816b531609 100644 --- a/includes/job/jobs/EnotifNotifyJob.php +++ b/includes/job/jobs/EnotifNotifyJob.php @@ -27,7 +27,6 @@ * @ingroup JobQueue */ class EnotifNotifyJob extends Job { - function __construct( $title, $params, $id = 0 ) { parent::__construct( 'enotifNotify', $title, $params, $id ); } @@ -52,7 +51,7 @@ class EnotifNotifyJob extends Job { $this->params['watchers'], $this->params['pageStatus'] ); + return true; } - } diff --git a/includes/job/jobs/HTMLCacheUpdateJob.php b/includes/job/jobs/HTMLCacheUpdateJob.php index be129371f9..1dd77ede3c 100644 --- a/includes/job/jobs/HTMLCacheUpdateJob.php +++ b/includes/job/jobs/HTMLCacheUpdateJob.php @@ -86,6 +86,7 @@ class HTMLCacheUpdateJob extends Job { $numRows = $this->blCache->getNumLinks( $this->params['table'], $max ); if ( $wgMaxBacklinksInvalidate !== false && $numRows > $wgMaxBacklinksInvalidate ) { wfDebug( "Skipped HTML cache invalidation of {$this->title->getPrefixedText()}." ); + return true; } @@ -123,6 +124,7 @@ class HTMLCacheUpdateJob extends Job { # period of time, say by updating a heavily-used template. $this->insertJobsFromTitles( $titleArray ); } + return true; } diff --git a/includes/job/jobs/NullJob.php b/includes/job/jobs/NullJob.php index b6164a5d57..77f65728b0 100644 --- a/includes/job/jobs/NullJob.php +++ b/includes/job/jobs/NullJob.php @@ -71,6 +71,7 @@ class NullJob extends Job { $job = new self( $this->title, $params ); JobQueueGroup::singleton()->push( $job ); } + return true; } } diff --git a/includes/job/jobs/PublishStashedFileJob.php b/includes/job/jobs/PublishStashedFileJob.php index 1276e3ccaa..ba47cb903f 100644 --- a/includes/job/jobs/PublishStashedFileJob.php +++ b/includes/job/jobs/PublishStashedFileJob.php @@ -39,6 +39,7 @@ class PublishStashedFileJob extends Job { $user = $context->getUser(); if ( !$user->isLoggedIn() ) { $this->setLastError( "Could not load the author user from session." ); + return false; } @@ -48,6 +49,7 @@ class PublishStashedFileJob extends Job { // the user does not necessarily mean the session was loaded. // Most likely cause by suhosin.session.encrypt = On. $this->setLastError( "Error associating with user session. Try setting suhosin.session.encrypt = Off" ); + return false; } @@ -73,6 +75,7 @@ class PublishStashedFileJob extends Job { array( 'result' => 'Failure', 'stage' => 'publish', 'status' => $status ) ); $this->setLastError( "Could not verify upload." ); + return false; } @@ -89,6 +92,7 @@ class PublishStashedFileJob extends Job { array( 'result' => 'Failure', 'stage' => 'publish', 'status' => $status ) ); $this->setLastError( $status->getWikiText() ); + return false; } @@ -120,8 +124,10 @@ class PublishStashedFileJob extends Job { ) ); $this->setLastError( get_class( $e ) . ": " . $e->getText() ); + return false; } + return true; } @@ -130,6 +136,7 @@ class PublishStashedFileJob extends Job { if ( is_array( $info['params'] ) ) { $info['params'] = array( 'filekey' => $info['params']['filekey'] ); } + return $info; } diff --git a/includes/job/jobs/RefreshLinksJob.php b/includes/job/jobs/RefreshLinksJob.php index 4fc8bac623..377fea58e6 100644 --- a/includes/job/jobs/RefreshLinksJob.php +++ b/includes/job/jobs/RefreshLinksJob.php @@ -42,6 +42,7 @@ class RefreshLinksJob extends Job { if ( is_null( $this->title ) ) { $this->error = "refreshLinks: Invalid title"; + return false; } @@ -56,6 +57,7 @@ class RefreshLinksJob extends Job { if ( !$revision ) { $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"'; + return false; // XXX: what if it was just deleted? } @@ -73,6 +75,7 @@ class RefreshLinksJob extends Job { if ( is_array( $info['params'] ) ) { unset( $info['params']['masterPos'] ); } + return $info; } @@ -128,6 +131,7 @@ class RefreshLinksJob2 extends Job { if ( is_null( $this->title ) ) { $this->error = "refreshLinks2: Invalid title"; + return false; } @@ -205,6 +209,7 @@ class RefreshLinksJob2 extends Job { array( 'masterPos' => $masterPos ) + $this->getRootJobParams() ); // carry over information for de-duplication } + return $jobs; } @@ -217,6 +222,7 @@ class RefreshLinksJob2 extends Job { if ( is_array( $info['params'] ) ) { unset( $info['params']['masterPos'] ); } + return $info; } } diff --git a/includes/job/jobs/UploadFromUrlJob.php b/includes/job/jobs/UploadFromUrlJob.php index c993cfb476..1354169024 100644 --- a/includes/job/jobs/UploadFromUrlJob.php +++ b/includes/job/jobs/UploadFromUrlJob.php @@ -66,6 +66,7 @@ class UploadFromUrlJob extends Job { $status = $this->upload->fetchFile( $opts ); if ( !$status->isOk() ) { $this->leaveMessage( $status ); + return true; } @@ -74,6 +75,7 @@ class UploadFromUrlJob extends Job { if ( $result['status'] != UploadBase::OK ) { $status = $this->upload->convertVerifyErrorToStatus( $result ); $this->leaveMessage( $status ); + return true; } @@ -111,8 +113,8 @@ class UploadFromUrlJob extends Job { $this->user ); $this->leaveMessage( $status ); - return true; + return true; } /** @@ -179,6 +181,7 @@ class UploadFromUrlJob extends Job { if ( !isset( $_SESSION[self::SESSION_KEYNAME][$key] ) ) { $_SESSION[self::SESSION_KEYNAME][$key] = array(); } + return $_SESSION[self::SESSION_KEYNAME][$key]; } }