}
protected function supportedOrders() {
- return array( 'random', 'timestamp', 'fifo' );
+ return [ 'random', 'timestamp', 'fifo' ];
}
protected function optimalOrder() {
$dbr = $this->getSlaveDB();
try {
$found = $dbr->selectField( // unclaimed job
- 'job', '1', array( 'job_cmd' => $this->type, 'job_token' => '' ), __METHOD__
+ 'job', '1', [ 'job_cmd' => $this->type, 'job_token' => '' ], __METHOD__
);
} catch ( DBError $e ) {
$this->throwDBException( $e );
try {
$dbr = $this->getSlaveDB();
$size = (int)$dbr->selectField( 'job', 'COUNT(*)',
- array( 'job_cmd' => $this->type, 'job_token' => '' ),
+ [ 'job_cmd' => $this->type, 'job_token' => '' ],
__METHOD__
);
} catch ( DBError $e ) {
$dbr = $this->getSlaveDB();
try {
$count = (int)$dbr->selectField( 'job', 'COUNT(*)',
- array( 'job_cmd' => $this->type, "job_token != {$dbr->addQuotes( '' )}" ),
+ [ 'job_cmd' => $this->type, "job_token != {$dbr->addQuotes( '' )}" ],
__METHOD__
);
} catch ( DBError $e ) {
$dbr = $this->getSlaveDB();
try {
$count = (int)$dbr->selectField( 'job', 'COUNT(*)',
- array(
+ [
'job_cmd' => $this->type,
"job_token != {$dbr->addQuotes( '' )}",
"job_attempts >= " . $dbr->addQuotes( $this->maxTries )
- ),
+ ],
__METHOD__
);
} catch ( DBError $e ) {
protected function doBatchPush( array $jobs, $flags ) {
$dbw = $this->getMasterDB();
- $that = $this;
$method = __METHOD__;
$dbw->onTransactionIdle(
- function () use ( $dbw, $that, $jobs, $flags, $method ) {
- $that->doBatchPushInternal( $dbw, $jobs, $flags, $method );
+ function () use ( $dbw, $jobs, $flags, $method ) {
+ $this->doBatchPushInternal( $dbw, $jobs, $flags, $method );
}
);
}
return;
}
- $rowSet = array(); // (sha1 => job) map for jobs that are de-duplicated
- $rowList = array(); // list of jobs for jobs that are not de-duplicated
+ $rowSet = []; // (sha1 => job) map for jobs that are de-duplicated
+ $rowList = []; // list of jobs for jobs that are not de-duplicated
foreach ( $jobs as $job ) {
$row = $this->insertFields( $job );
if ( $job->ignoreDuplicates() ) {
// Strip out any duplicate jobs that are already in the queue...
if ( count( $rowSet ) ) {
$res = $dbw->select( 'job', 'job_sha1',
- array(
+ [
// No job_type condition since it's part of the job_sha1 hash
'job_sha1' => array_keys( $rowSet ),
'job_token' => '' // unclaimed
- ),
+ ],
$method
);
foreach ( $res as $row ) {
$job = false; // job popped off
do { // retry when our row is invalid or deleted as a duplicate
// Try to reserve a row in the DB...
- if ( in_array( $this->order, array( 'fifo', 'timestamp' ) ) ) {
+ if ( in_array( $this->order, [ 'fifo', 'timestamp' ] ) ) {
$row = $this->claimOldest( $uuid );
} else { // random first
$rand = mt_rand( 0, self::MAX_JOB_RANDOM ); // encourage concurrent UPDATEs
$ineq = $gte ? '>=' : '<=';
$dir = $gte ? 'ASC' : 'DESC';
$row = $dbw->selectRow( 'job', self::selectFields(), // find a random job
- array(
+ [
'job_cmd' => $this->type,
'job_token' => '', // unclaimed
- "job_random {$ineq} {$dbw->addQuotes( $rand )}" ),
+ "job_random {$ineq} {$dbw->addQuotes( $rand )}" ],
__METHOD__,
- array( 'ORDER BY' => "job_random {$dir}" )
+ [ 'ORDER BY' => "job_random {$dir}" ]
);
if ( !$row && !$invertedDirection ) {
$gte = !$gte;
// in MySQL if there are many rows for some reason. This uses a small OFFSET
// instead of job_random for reducing excess claim retries.
$row = $dbw->selectRow( 'job', self::selectFields(), // find a random job
- array(
+ [
'job_cmd' => $this->type,
'job_token' => '', // unclaimed
- ),
+ ],
__METHOD__,
- array( 'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) )
+ [ 'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) ]
);
if ( !$row ) {
$tinyQueue = true; // we know the queue must have <= MAX_OFFSET rows
if ( $row ) { // claim the job
$dbw->update( 'job', // update by PK
- array(
+ [
'job_token' => $uuid,
'job_token_timestamp' => $dbw->timestamp(),
- 'job_attempts = job_attempts+1' ),
- array( 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' ),
+ 'job_attempts = job_attempts+1' ],
+ [ 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' ],
__METHOD__
);
// This might get raced out by another runner when claiming the previously
// Use a subquery to find the job, within an UPDATE to claim it.
// This uses as much of the DB wrapper functions as possible.
$dbw->update( 'job',
- array(
+ [
'job_token' => $uuid,
'job_token_timestamp' => $dbw->timestamp(),
- 'job_attempts = job_attempts+1' ),
- array( 'job_id = (' .
+ 'job_attempts = job_attempts+1' ],
+ [ 'job_id = (' .
$dbw->selectSQLText( 'job', 'job_id',
- array( 'job_cmd' => $this->type, 'job_token' => '' ),
+ [ 'job_cmd' => $this->type, 'job_token' => '' ],
__METHOD__,
- array( 'ORDER BY' => 'job_id ASC', 'LIMIT' => 1 ) ) .
+ [ 'ORDER BY' => 'job_id ASC', 'LIMIT' => 1 ] ) .
')'
- ),
+ ],
__METHOD__
);
}
// Fetch any row that we just reserved...
if ( $dbw->affectedRows() ) {
$row = $dbw->selectRow( 'job', self::selectFields(),
- array( 'job_cmd' => $this->type, 'job_token' => $uuid ), __METHOD__
+ [ 'job_cmd' => $this->type, 'job_token' => $uuid ], __METHOD__
);
if ( !$row ) { // raced out by duplicate job removal
wfDebug( "Row deleted as duplicate by another process.\n" );
* @see JobQueue::doAck()
* @param Job $job
* @throws MWException
- * @return Job|bool
*/
protected function doAck( Job $job ) {
if ( !isset( $job->metadata['id'] ) ) {
// Delete a row with a single DELETE without holding row locks over RTTs...
$dbw->delete( 'job',
- array( 'job_cmd' => $this->type, 'job_id' => $job->metadata['id'] ), __METHOD__ );
+ [ 'job_cmd' => $this->type, 'job_id' => $job->metadata['id'] ], __METHOD__ );
JobQueue::incrStats( 'acks', $this->type );
} catch ( DBError $e ) {
$this->throwDBException( $e );
}
-
- return true;
}
/**
protected function doDelete() {
$dbw = $this->getMasterDB();
try {
- $dbw->delete( 'job', array( 'job_cmd' => $this->type ) );
+ $dbw->delete( 'job', [ 'job_cmd' => $this->type ] );
} catch ( DBError $e ) {
$this->throwDBException( $e );
}
* @return void
*/
protected function doFlushCaches() {
- foreach ( array( 'size', 'acquiredcount' ) as $type ) {
+ foreach ( [ 'size', 'acquiredcount' ] as $type ) {
$this->cache->delete( $this->getCacheKey( $type ) );
}
}
* @return Iterator
*/
public function getAllQueuedJobs() {
- return $this->getJobIterator( array( 'job_cmd' => $this->getType(), 'job_token' => '' ) );
+ return $this->getJobIterator( [ 'job_cmd' => $this->getType(), 'job_token' => '' ] );
}
/**
* @return Iterator
*/
public function getAllAcquiredJobs() {
- return $this->getJobIterator( array( 'job_cmd' => $this->getType(), "job_token > ''" ) );
+ return $this->getJobIterator( [ 'job_cmd' => $this->getType(), "job_token > ''" ] );
}
/**
$job = Job::factory(
$row->job_cmd,
Title::makeTitle( $row->job_namespace, $row->job_title ),
- strlen( $row->job_params ) ? unserialize( $row->job_params ) : array()
+ strlen( $row->job_params ) ? unserialize( $row->job_params ) : []
);
$job->metadata['id'] = $row->job_id;
$job->metadata['timestamp'] = $row->job_timestamp;
// have stale jobs. This lets recycleAndDeleteStaleJobs() re-enqueue
// failed jobs so that they can be popped again for that edge case.
$res = $dbr->select( 'job', 'DISTINCT job_cmd',
- array( 'job_cmd' => $types ), __METHOD__ );
+ [ 'job_cmd' => $types ], __METHOD__ );
- $types = array();
+ $types = [];
foreach ( $res as $row ) {
$types[] = $row->job_cmd;
}
protected function doGetSiblingQueueSizes( array $types ) {
$dbr = $this->getSlaveDB();
- $res = $dbr->select( 'job', array( 'job_cmd', 'COUNT(*) AS count' ),
- array( 'job_cmd' => $types ), __METHOD__, array( 'GROUP BY' => 'job_cmd' ) );
+ $res = $dbr->select( 'job', [ 'job_cmd', 'COUNT(*) AS count' ],
+ [ 'job_cmd' => $types ], __METHOD__, [ 'GROUP BY' => 'job_cmd' ] );
- $sizes = array();
+ $sizes = [];
foreach ( $res as $row ) {
$sizes[$row->job_cmd] = (int)$row->count;
}
// These jobs can be recycled into the queue by expiring the claim. Selecting
// the IDs first means that the UPDATE can be done by primary key (less deadlocks).
$res = $dbw->select( 'job', 'job_id',
- array(
+ [
'job_cmd' => $this->type,
"job_token != {$dbw->addQuotes( '' )}", // was acquired
"job_token_timestamp < {$dbw->addQuotes( $claimCutoff )}", // stale
- "job_attempts < {$dbw->addQuotes( $this->maxTries )}" ), // retries left
+ "job_attempts < {$dbw->addQuotes( $this->maxTries )}" ], // retries left
__METHOD__
);
$ids = array_map(
// Set the timestamp to the current time, as it is useful to now that the job
// was already tried before (the timestamp becomes the "released" time).
$dbw->update( 'job',
- array(
+ [
'job_token' => '',
- 'job_token_timestamp' => $dbw->timestamp( $now ) ), // time of release
- array(
- 'job_id' => $ids ),
+ 'job_token_timestamp' => $dbw->timestamp( $now ) ], // time of release
+ [
+ 'job_id' => $ids ],
__METHOD__
);
$affected = $dbw->affectedRows();
// Just destroy any stale jobs...
$pruneCutoff = $dbw->timestamp( $now - self::MAX_AGE_PRUNE );
- $conds = array(
+ $conds = [
'job_cmd' => $this->type,
"job_token != {$dbw->addQuotes( '' )}", // was acquired
"job_token_timestamp < {$dbw->addQuotes( $pruneCutoff )}" // stale
- );
+ ];
if ( $this->claimTTL > 0 ) { // only prune jobs attempted too many times...
$conds[] = "job_attempts >= {$dbw->addQuotes( $this->maxTries )}";
}
}, iterator_to_array( $res )
);
if ( count( $ids ) ) {
- $dbw->delete( 'job', array( 'job_id' => $ids ), __METHOD__ );
+ $dbw->delete( 'job', [ 'job_id' => $ids ], __METHOD__ );
$affected = $dbw->affectedRows();
$count += $affected;
JobQueue::incrStats( 'abandons', $this->type, $affected );
protected function insertFields( IJobSpecification $job ) {
$dbw = $this->getMasterDB();
- return array(
+ return [
// Fields that describe the nature of the job
'job_cmd' => $job->getType(),
'job_namespace' => $job->getTitle()->getNamespace(),
16, 36, 31
),
'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
- );
+ ];
}
/**
? wfGetLBFactory()->getExternalLB( $this->cluster, $this->wiki )
: wfGetLB( $this->wiki );
- return $lb->getConnectionRef( $index, array(), $this->wiki );
+ return $lb->getConnectionRef( $index, [], $this->wiki );
}
/**
* @return array
*/
public static function selectFields() {
- return array(
+ return [
'job_id',
'job_cmd',
'job_namespace',
'job_token',
'job_token_timestamp',
'job_sha1',
- );
+ ];
}
}