Merge "build: Update eslint-config-wikimedia to 0.7.2"
[lhc/web/wiklou.git] / includes / jobqueue / JobQueueDB.php
index c3193c3..689326e 100644 (file)
@@ -55,7 +55,7 @@ class JobQueueDB extends JobQueue {
        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();
        }
 
@@ -221,7 +221,7 @@ class JobQueueDB extends JobQueue {
                $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 {
@@ -500,14 +500,14 @@ class JobQueueDB extends JobQueue {
                        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'] ) {
@@ -722,11 +722,10 @@ class JobQueueDB extends JobQueue {
 
        /**
         * @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(),
@@ -734,7 +733,7 @@ class JobQueueDB extends JobQueue {
                        '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