3 * Router job that takes jobs and enqueues them.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Router job that takes jobs and enqueues them to their proper queues
27 * This can be used for several things:
28 * - a) Making multi-job enqueues more robust by atomically enqueueing
29 * a single job that pushes the actual jobs (with retry logic)
30 * - b) Masking the latency of pushing jobs to different queues/wikis
31 * - c) Low-latency enqueues to push jobs from warm to hot datacenters
36 final class EnqueueJob
extends Job
{
38 * Callers should use the factory methods instead
41 * @param array $params Job parameters
43 function __construct( Title
$title, array $params ) {
44 parent
::__construct( 'enqueue', $title, $params );
48 * @param JobSpecification|JobSpecification[] $jobs
51 public static function newFromLocalJobs( $jobs ) {
52 $jobs = is_array( $jobs ) ?
$jobs : array( $jobs );
54 return self
::newFromJobsByWiki( array( wfWikiID() => $jobs ) );
58 * @param array $jobsByWiki Map of (wiki => JobSpecification list)
61 public static function newFromJobsByWiki( array $jobsByWiki ) {
62 $jobMapsByWiki = array();
63 foreach ( $jobsByWiki as $wiki => $jobs ) {
64 $jobMapsByWiki[$wiki] = array();
65 foreach ( $jobs as $job ) {
66 if ( $job instanceof JobSpecification
) {
67 $jobMapsByWiki[$wiki][] = $job->toSerializableArray();
69 throw new InvalidArgumentException( "Jobs must be of type JobSpecification." );
74 return new self( Title
::newMainPage(), array( 'jobsByWiki' => $jobMapsByWiki ) );
77 public function run() {
78 foreach ( $this->params
['jobsByWiki'] as $wiki => $jobMaps ) {
80 foreach ( $jobMaps as $jobMap ) {
81 $jobSpecs[] = JobSpecification
::newFromArray( $jobMap );
83 JobQueueGroup
::singleton( $wiki )->push( $jobSpecs );