* Job queue task description base code
*
* Example usage:
- * <code>
+ * @code
* $job = new JobSpecification(
* 'null',
* array( 'lives' => 1, 'usleep' => 100, 'pi' => 3.141569 ),
* Title::makeTitle( NS_SPECIAL, 'nullity' )
* );
* JobQueueGroup::singleton()->push( $job )
- * </code>
+ * @endcode
*
* @ingroup JobQueue
* @since 1.23
/** @var Title */
protected $title;
- /** @var bool Expensive jobs may set this to true */
- protected $ignoreDuplicates;
+ /** @var array */
+ protected $opts;
/**
* @param string $type
$type, array $params, array $opts = array(), Title $title = null
) {
$this->validateParams( $params );
+ $this->validateParams( $opts );
$this->type = $type;
$this->params = $params;
- $this->title = $title ?: Title::newMainPage();
- $this->ignoreDuplicates = !empty( $opts['removeDuplicates'] );
+ $this->title = $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . get_class( $this ) );
+ $this->opts = $opts;
}
/**
if ( is_array( $v ) ) {
$this->validateParams( $v );
} elseif ( !is_scalar( $v ) && $v !== null ) {
- throw new UnexpectedValueException( 'Job parameters are not JSON serializable.' );
+ throw new UnexpectedValueException( "Job parameter $p is not JSON serializable." );
}
}
}
* @return bool Whether only one of each identical set of jobs should be run
*/
public function ignoreDuplicates() {
- return $this->ignoreDuplicates;
+ return !empty( $this->opts['removeDuplicates'] );
}
/**
return $info;
}
+
+ /**
+ * @return array Field/value map that can immediately be serialized
+ * @since 1.25
+ */
+ public function toSerializableArray() {
+ return array(
+ 'type' => $this->type,
+ 'params' => $this->params,
+ 'opts' => $this->opts,
+ 'title' => array(
+ 'ns' => $this->title->getNamespace(),
+ 'key' => $this->title->getDbKey()
+ )
+ );
+ }
+
+ /**
+ * @param array $map Field/value map
+ * @return JobSpecification
+ * @since 1.25
+ */
+ public static function newFromArray( array $map ) {
+ $title = Title::makeTitle( $map['title']['ns'], $map['title']['key'] );
+
+ return new self( $map['type'], $map['params'], $map['opts'], $title );
+ }
}