protected function __construct( array $params ) {
parent::__construct( $params );
- $this->cluster = isset( $params['cluster'] ) ? $params['cluster'] : false;
+ $this->cluster = $params['cluster'] ?? false;
$this->cache = ObjectCache::getMainWANInstance();
}
$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 );
+ $row = $this->insertFields( $job, $dbw );
if ( $job->ignoreDuplicates() ) {
$rowSet[$row['job_sha1']] = $row;
} else {
throw new MWException( "Cannot register root job; missing 'rootJobTimestamp'." );
}
$key = $this->getRootJobCacheKey( $params['rootJobSignature'] );
- // Callers should call batchInsert() and then this function so that if the insert
+ // Callers should call JobQueueGroup::push() before this method so that if the insert
// fails, the de-duplication registration will be aborted. Since the insert is
// deferred till "transaction idle", do the same here, so that the ordering is
// maintained. Having only the de-duplication registration succeed would cause
// jobs to become no-ops without any actual jobs that made them redundant.
$dbw = $this->getMasterDB();
$cache = $this->dupCache;
- $dbw->onTransactionIdle(
+ $dbw->onTransactionCommitOrIdle(
function () use ( $cache, $params, $key ) {
$timestamp = $cache->get( $key ); // current last timestamp of this job
if ( $timestamp && $timestamp >= $params['rootJobTimestamp'] ) {
/**
* @param IJobSpecification $job
+ * @param IDatabase $db
* @return array
*/
- protected function insertFields( IJobSpecification $job ) {
- $dbw = $this->getMasterDB();
-
+ protected function insertFields( IJobSpecification $job, IDatabase $db ) {
return [
// Fields that describe the nature of the job
'job_cmd' => $job->getType(),
'job_title' => $job->getTitle()->getDBkey(),
'job_params' => self::makeBlob( $job->getParams() ),
// Additional job metadata
- 'job_timestamp' => $dbw->timestamp(),
+ 'job_timestamp' => $db->timestamp(),
'job_sha1' => Wikimedia\base_convert(
sha1( serialize( $job->getDeduplicationInfo() ) ),
16, 36, 31