/** * @param IJobSpecification $job * @return array */ protected function insertFields(IJobSpecification $job) { $dbw = $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' => Wikimedia\base_convert(sha1(serialize($job->getDeduplicationInfo())), 16, 36, 31), 'job_random' => mt_rand(0, self::MAX_JOB_RANDOM)); }
/** * @param IJobSpecification $spec * * @return Job */ public function jobFromSpecInternal(IJobSpecification $spec) { return Job::factory($spec->getType(), $spec->getTitle(), $spec->getParams()); }
/** * @see JobQueue::deduplicateRootJob() * @param IJobSpecification $job * @throws MWException * @return bool */ protected function doDeduplicateRootJob(IJobSpecification $job) { if (!$job->hasRootJobParams()) { throw new MWException("Cannot register root job; missing parameters."); } $params = $job->getRootJobParams(); $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. $timestamp = $this->dupCache->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 $this->dupCache->set($key, $params['rootJobTimestamp'], JobQueueDB::ROOTJOB_TTL); }
/** * @param IJobSpecification $job * @return array */ protected function getNewJobFields(IJobSpecification $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() ? Wikimedia\base_convert(sha1(serialize($job->getDeduplicationInfo())), 16, 36, 31) : '', 'timestamp' => time()); }
protected function doDeduplicateRootJob(IJobSpecification $job) { $params = $job->getRootJobParams(); $sigature = $params['rootJobSignature']; $partition = $this->partitionRing->getLiveLocation($sigature); try { return $this->partitionQueues[$partition]->doDeduplicateRootJob($job); } catch (JobQueueError $e) { if ($this->partitionRing->ejectFromLiveRing($partition, 5)) { $partition = $this->partitionRing->getLiveLocation($sigature); return $this->partitionQueues[$partition]->doDeduplicateRootJob($job); } } return false; }