MediaWiki REL1_31
EnqueueJob.php
Go to the documentation of this file.
1<?php
35final class EnqueueJob extends Job {
42 function __construct( Title $title, array $params ) {
43 parent::__construct( 'enqueue', $title, $params );
44 }
45
50 public static function newFromLocalJobs( $jobs ) {
51 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
52
53 return self::newFromJobsByWiki( [ wfWikiID() => $jobs ] );
54 }
55
60 public static function newFromJobsByWiki( array $jobsByWiki ) {
61 $deduplicate = true;
62
63 $jobMapsByWiki = [];
64 foreach ( $jobsByWiki as $wiki => $jobs ) {
65 $jobMapsByWiki[$wiki] = [];
66 foreach ( $jobs as $job ) {
67 if ( $job instanceof JobSpecification ) {
68 $jobMapsByWiki[$wiki][] = $job->toSerializableArray();
69 } else {
70 throw new InvalidArgumentException( "Jobs must be of type JobSpecification." );
71 }
72 $deduplicate = $deduplicate && $job->ignoreDuplicates();
73 }
74 }
75
76 $eJob = new self(
77 Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __CLASS__ ),
78 [ 'jobsByWiki' => $jobMapsByWiki ]
79 );
80 // If *all* jobs to be pushed are to be de-duplicated (a common case), then
81 // de-duplicate this whole job itself to avoid build up in high traffic cases
82 $eJob->removeDuplicates = $deduplicate;
83
84 return $eJob;
85 }
86
87 public function run() {
88 foreach ( $this->params['jobsByWiki'] as $wiki => $jobMaps ) {
89 $jobSpecs = [];
90 foreach ( $jobMaps as $jobMap ) {
91 $jobSpecs[] = JobSpecification::newFromArray( $jobMap );
92 }
93 JobQueueGroup::singleton( $wiki )->push( $jobSpecs );
94 }
95
96 return true;
97 }
98}
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( $domain=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:63
if(count( $args)< 1) $job