* Class to handle job queues stored in the DB
*
* @ingroup JobQueue
- * @since 1.20
+ * @since 1.21
*/
class JobQueueDB extends JobQueue {
- const CACHE_TTL = 30; // integer; seconds
+ const CACHE_TTL = 300; // integer; seconds
const MAX_JOB_RANDOM = 2147483647; // 2^31 - 1; used for job_random
/**
$dbw->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore automatic begin()
}
- $wgMemc->set( $key, 'false', $ttl );
+ $wgMemc->set( $key, 'false', $ttl ); // queue is not empty
} );
}
$title = Title::makeTitleSafe( $row->job_namespace, $row->job_title );
if ( !$title ) {
$dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ );
+ wfIncrStats( 'job-pop' );
wfDebugLog( 'JobQueueDB', "Row has invalid title '{$row->job_title}'." );
continue; // try again
}
"job_id != {$dbw->addQuotes( $row->job_id )}" ),
__METHOD__
);
+ wfIncrStats( 'job-pop', $dbw->affectedRows() );
}
break; // done
} while( true );
*/
protected function doAck( Job $job ) {
$dbw = $this->getMasterDB();
- if ( $dbw->trxLevel() ) {
- wfWarn( "Attempted to ack a job in a transaction; committing first." );
- $dbw->commit(); // push existing transaction
- }
+ $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction
$autoTrx = $dbw->getFlag( DBO_TRX ); // automatic begin() enabled?
$dbw->clearFlag( DBO_TRX ); // make each query its own transaction
'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ),
'job_timestamp' => $dbw->timestamp(),
'job_sha1' => wfBaseConvert( sha1( serialize( $descFields ) ), 16, 36, 32 ),
- 'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
+ 'job_random' => $random
);
return ( $descFields + $metaFields );
}