MediaWiki REL1_39
EnqueueJob.php
Go to the documentation of this file.
1<?php
25
37final class EnqueueJob extends Job implements GenericParameterJob {
43 public function __construct( array $params ) {
44 parent::__construct( 'enqueue', $params );
45 }
46
51 public static function newFromLocalJobs( $jobs ) {
52 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
53
54 return self::newFromJobsByDomain( [
55 WikiMap::getCurrentWikiDbDomain()->getId() => $jobs
56 ] );
57 }
58
63 public static function newFromJobsByDomain( array $jobsByDomain ) {
64 $deduplicate = true;
65
66 $jobMapsByDomain = [];
67 foreach ( $jobsByDomain as $domain => $jobs ) {
68 $jobMapsByDomain[$domain] = [];
69 foreach ( $jobs as $job ) {
70 if ( $job instanceof JobSpecification ) {
71 $jobMapsByDomain[$domain][] = $job->toSerializableArray();
72 } else {
73 throw new InvalidArgumentException( "Jobs must be of type JobSpecification." );
74 }
75 $deduplicate = $deduplicate && $job->ignoreDuplicates();
76 }
77 }
78
79 $eJob = new self( [ 'jobsByDomain' => $jobMapsByDomain ] );
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
92 public static function newFromJobsByWiki( array $jobsByWiki ) {
93 wfDeprecated( __METHOD__, '1.33' );
94 return self::newFromJobsByDomain( $jobsByWiki );
95 }
96
97 public function run() {
98 $jobsByDomain = $this->params['jobsByDomain'] ?? $this->params['jobsByWiki']; // b/c
99
100 $jobQueueGroupFactory = MediaWikiServices::getInstance()->getJobQueueGroupFactory();
101 foreach ( $jobsByDomain as $domain => $jobMaps ) {
102 $jobSpecs = [];
103 foreach ( $jobMaps as $jobMap ) {
104 $jobSpecs[] = JobSpecification::newFromArray( $jobMap );
105 }
106 $jobQueueGroupFactory->makeJobQueueGroup( $domain )->push( $jobSpecs );
107 }
108
109 return true;
110 }
111}
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Router job that takes jobs and enqueues them to their proper queues.
static newFromJobsByWiki(array $jobsByWiki)
run()
Run the job.
static newFromLocalJobs( $jobs)
__construct(array $params)
Callers should use the factory methods instead.
static newFromJobsByDomain(array $jobsByDomain)
Job queue task description base code.
Class to both describe a background job and handle jobs.
Definition Job.php:39
Service locator for MediaWiki core services.
Interface for generic jobs only uses the parameters field and are JSON serializable.
if(count( $args)< 1) $job