$failed += count( $itemBatch );
}
}
- JobQueue::incrStats( 'inserts', $this->type, count( $items ) );
- JobQueue::incrStats( 'inserts_actual', $this->type, $pushed );
- JobQueue::incrStats( 'dupe_inserts', $this->type,
+ $this->incrStats( 'inserts', $this->type, count( $items ) );
+ $this->incrStats( 'inserts_actual', $this->type, $pushed );
+ $this->incrStats( 'dupe_inserts', $this->type,
count( $items ) - $failed - $pushed );
if ( $failed > 0 ) {
$err = "Could not insert {$failed} {$this->type} job(s).";
/**
* @see JobQueue::doPop()
- * @return Job|bool
+ * @return RunnableJob|bool
* @throws JobQueueError
*/
protected function doPop() {
break; // no jobs; nothing to do
}
- JobQueue::incrStats( 'pops', $this->type );
+ $this->incrStats( 'pops', $this->type );
$item = $this->unserialize( $blob );
if ( $item === false ) {
wfDebugLog( 'JobQueueRedis', "Could not unserialize {$this->type} job." );
/**
* @see JobQueue::doAck()
- * @param Job $job
- * @return Job|bool
+ * @param RunnableJob $job
+ * @return RunnableJob|bool
* @throws UnexpectedValueException
* @throws JobQueueError
*/
- protected function doAck( Job $job ) {
- if ( !isset( $job->metadata['uuid'] ) ) {
+ protected function doAck( RunnableJob $job ) {
+ $uuid = $job->getMetadata( 'uuid' );
+ if ( $uuid === null ) {
throw new UnexpectedValueException( "Job of type '{$job->getType()}' has no UUID." );
}
- $uuid = $job->metadata['uuid'];
$conn = $this->getConnection();
try {
static $script =
return false;
}
- JobQueue::incrStats( 'acks', $this->type );
+ $this->incrStats( 'acks', $this->type );
} catch ( RedisException $e ) {
$this->throwRedisException( $conn, $e );
}
/**
* @see JobQueue::doIsRootJobOldDuplicate()
- * @param Job $job
+ * @param IJobSpecification $job
* @return bool
* @throws JobQueueError
*/
- protected function doIsRootJobOldDuplicate( Job $job ) {
+ protected function doIsRootJobOldDuplicate( IJobSpecification $job ) {
if ( !$job->hasRootJobParams() ) {
return false; // job has no de-deplication info
}
*
* @param string $uid
* @param RedisConnRef $conn
- * @return Job|bool Returns false if the job does not exist
+ * @return RunnableJob|bool Returns false if the job does not exist
* @throws JobQueueError
* @throws UnexpectedValueException
*/
}
$item = $this->unserialize( $data );
if ( !is_array( $item ) ) { // this shouldn't happen
- throw new UnexpectedValueException( "Could not find job with ID '$uid'." );
+ throw new UnexpectedValueException( "Could not unserialize job with ID '$uid'." );
}
- $title = Title::makeTitle( $item['namespace'], $item['title'] );
- $job = Job::factory( $item['type'], $title, $item['params'] );
- $job->metadata['uuid'] = $item['uuid'];
- $job->metadata['timestamp'] = $item['timestamp'];
+
+ $params = $item['params'];
+ $params += [ 'namespace' => $item['namespace'], 'title' => $item['title'] ];
+ $job = $this->factoryJob( $item['type'], $params );
+ $job->setMetadata( 'uuid', $item['uuid'] );
+ $job->setMetadata( 'timestamp', $item['timestamp'] );
// Add in attempt count for debugging at showJobs.php
- $job->metadata['attempts'] = $conn->hGet( $this->getQueueKey( 'h-attempts' ), $uid );
+ $job->setMetadata( 'attempts',
+ $conn->hGet( $this->getQueueKey( 'h-attempts' ), $uid ) );
return $job;
} catch ( RedisException $e ) {
return [
// Fields that describe the nature of the job
'type' => $job->getType(),
- 'namespace' => $job->getTitle()->getNamespace(),
- 'title' => $job->getTitle()->getDBkey(),
+ 'namespace' => $job->getParams()['namespace'] ?? NS_SPECIAL,
+ 'title' => $job->getParams()['title'] ?? '',
'params' => $job->getParams(),
// Some jobs cannot run until a "release timestamp"
'rtimestamp' => $job->getReleaseTimestamp() ?: 0,
/**
* @param array $fields
- * @return Job|bool
+ * @return RunnableJob|bool
*/
protected function getJobFromFields( array $fields ) {
- $title = Title::makeTitle( $fields['namespace'], $fields['title'] );
- $job = Job::factory( $fields['type'], $title, $fields['params'] );
- $job->metadata['uuid'] = $fields['uuid'];
- $job->metadata['timestamp'] = $fields['timestamp'];
+ $params = $fields['params'];
+ $params += [ 'namespace' => $fields['namespace'], 'title' => $fields['title'] ];
+
+ $job = $this->factoryJob( $fields['type'], $params );
+ $job->setMetadata( 'uuid', $fields['uuid'] );
+ $job->setMetadata( 'timestamp', $fields['timestamp'] );
return $job;
}