/** * Get a duplicate no-op version of a job * * @param Job $job * @return Job */ public static function newFromJob(Job $job) { $djob = new self($job->getTitle(), $job->getParams()); $djob->command = $job->getType(); $djob->params = is_array($djob->params) ? $djob->params : array(); $djob->params = array('isDuplicate' => true) + $djob->params; $djob->metadata = $job->metadata; return $djob; }
/** * @param $job Job * @return array */ protected function insertFields(Job $job) { list($dbw, $scope) = $this->getMasterDB(); return array('job_cmd' => $job->getType(), 'job_namespace' => $job->getTitle()->getNamespace(), 'job_title' => $job->getTitle()->getDBkey(), 'job_params' => self::makeBlob($job->getParams()), 'job_id' => $dbw->nextSequenceValue('job_job_id_seq'), 'job_timestamp' => $dbw->timestamp(), 'job_sha1' => wfBaseConvert(sha1(serialize($job->getDeduplicationInfo())), 16, 36, 31), 'job_random' => mt_rand(0, self::MAX_JOB_RANDOM)); }
/** * @param $job Job * @return array */ protected function getNewJobFields(Job $job) { return array('type' => $job->getType(), 'namespace' => $job->getTitle()->getNamespace(), 'title' => $job->getTitle()->getDBkey(), 'params' => $job->getParams(), 'rtimestamp' => $job->getReleaseTimestamp() ?: 0, 'uuid' => UIDGenerator::newRawUUIDv4(UIDGenerator::QUICK_RAND), 'sha1' => $job->ignoreDuplicates() ? wfBaseConvert(sha1(serialize($job->getDeduplicationInfo())), 16, 36, 31) : '', 'timestamp' => time()); }
/** * @see JobQueue::doDeduplicateRootJob() * @param Job $job * @throws MWException * @return bool */ protected function doDeduplicateRootJob(Job $job) { $params = $job->getParams(); if (!isset($params['rootJobSignature'])) { throw new MWException("Cannot register root job; missing 'rootJobSignature'."); } elseif (!isset($params['rootJobTimestamp'])) { 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 // 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(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 } // Update the timestamp of the last root job started at the location... return $cache->set($key, $params['rootJobTimestamp'], JobQueueDB::ROOTJOB_TTL); }); return true; }
/** * @param $job Job * @return array */ 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(), // Some jobs cannot run until a "release timestamp" '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 ); }
/** * @param $job Job * @return array */ protected function insertFields( Job $job ) { $dbw = $this->getMasterDB(); return array( // Fields that describe the nature of the job 'job_cmd' => $job->getType(), 'job_namespace' => $job->getTitle()->getNamespace(), 'job_title' => $job->getTitle()->getDBkey(), 'job_params' => self::makeBlob( $job->getParams() ), // Additional job metadata 'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ), 'job_timestamp' => $dbw->timestamp(), 'job_sha1' => wfBaseConvert( sha1( serialize( $job->getDeduplicationInfo() ) ), 16, 36, 31 ), 'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM ) ); }
/** * @param $job Job * @return array */ protected function insertFields(Job $job) { // Rows that describe the nature of the job $descFields = array('job_cmd' => $job->getType(), 'job_namespace' => $job->getTitle()->getNamespace(), 'job_title' => $job->getTitle()->getDBkey(), 'job_params' => self::makeBlob($job->getParams())); // Additional job metadata if ($this->order === 'timestamp') { // oldest first $random = time() - 1325376000; // seconds since "January 1, 2012" } else { // random first $random = mt_rand(0, self::MAX_JOB_RANDOM); } $dbw = $this->getMasterDB(); $metaFields = array('job_id' => $dbw->nextSequenceValue('job_job_id_seq'), 'job_timestamp' => $dbw->timestamp(), 'job_sha1' => wfBaseConvert(sha1(serialize($descFields)), 16, 36, 32), 'job_random' => $random); return $descFields + $metaFields; }