MediaWiki REL1_30
EnqueueJob.php
Go to the documentation of this file.
1<?php
36final class EnqueueJob extends Job {
43 function __construct( Title $title, array $params ) {
44 parent::__construct( 'enqueue', $title, $params );
45 }
46
51 public static function newFromLocalJobs( $jobs ) {
52 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
53
54 return self::newFromJobsByWiki( [ wfWikiID() => $jobs ] );
55 }
56
61 public static function newFromJobsByWiki( array $jobsByWiki ) {
62 $deduplicate = true;
63
64 $jobMapsByWiki = [];
65 foreach ( $jobsByWiki as $wiki => $jobs ) {
66 $jobMapsByWiki[$wiki] = [];
67 foreach ( $jobs as $job ) {
68 if ( $job instanceof JobSpecification ) {
69 $jobMapsByWiki[$wiki][] = $job->toSerializableArray();
70 } else {
71 throw new InvalidArgumentException( "Jobs must be of type JobSpecification." );
72 }
73 $deduplicate = $deduplicate && $job->ignoreDuplicates();
74 }
75 }
76
77 $eJob = new self(
78 Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __CLASS__ ),
79 [ 'jobsByWiki' => $jobMapsByWiki ]
80 );
81 // If *all* jobs to be pushed are to be de-duplicated (a common case), then
82 // de-duplicate this whole job itself to avoid build up in high traffic cases
83 $eJob->removeDuplicates = $deduplicate;
84
85 return $eJob;
86 }
87
88 public function run() {
89 foreach ( $this->params['jobsByWiki'] as $wiki => $jobMaps ) {
90 $jobSpecs = [];
91 foreach ( $jobMaps as $jobMap ) {
92 $jobSpecs[] = JobSpecification::newFromArray( $jobMap );
93 }
94 JobQueueGroup::singleton( $wiki )->push( $jobSpecs );
95 }
96
97 return true;
98 }
99}
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Router job that takes jobs and enqueues them to their proper queues.
static newFromJobsByWiki(array $jobsByWiki)
__construct(Title $title, array $params)
Callers should use the factory methods instead.
run()
Run the job.
static newFromLocalJobs( $jobs)
static singleton( $wiki=false)
Job queue task description base code.
static newFromArray(array $map)
Class to both describe a background job and handle jobs.
Definition Job.php:31
array $params
Array of job parameters.
Definition Job.php:36
Represents a title within MediaWiki.
Definition Title.php:39
const NS_SPECIAL
Definition Defines.php:54
if(count( $args)< 1) $job