MediaWiki  master
JobQueueEnqueueUpdate.php
Go to the documentation of this file.
1 <?php
25 use Wikimedia\Assert\Assert;
26 
35  private $jobsByDomain;
36 
39 
44  public function __construct( string $domain, array $jobs ) {
45  $this->jobsByDomain[$domain] = $jobs;
46  // TODO Inject services, when DeferredUpdates supports DI
47  $this->jobQueueGroupFactory = MediaWikiServices::getInstance()->getJobQueueGroupFactory();
48  }
49 
51  public function merge( MergeableUpdate $update ) {
53  Assert::parameterType( __CLASS__, $update, '$update' );
54  '@phan-var self $update';
55 
56  foreach ( $update->jobsByDomain as $domain => $jobs ) {
57  $this->jobsByDomain[$domain] = array_merge(
58  $this->jobsByDomain[$domain] ?? [],
59  $jobs
60  );
61  }
62  }
63 
65  public function doUpdate() {
66  foreach ( $this->jobsByDomain as $domain => $jobs ) {
67  $group = $this->jobQueueGroupFactory->makeJobQueueGroup( $domain );
68  try {
69  $group->push( $jobs );
70  } catch ( Throwable $e ) {
71  // Get in as many jobs as possible and let other post-send updates happen
73  }
74  }
75  }
76 }
JobQueueEnqueueUpdate\$jobQueueGroupFactory
JobQueueGroupFactory $jobQueueGroupFactory
Definition: JobQueueEnqueueUpdate.php:38
JobQueueEnqueueUpdate\doUpdate
doUpdate()
Perform the actual work.
Definition: JobQueueEnqueueUpdate.php:65
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:200
JobQueueEnqueueUpdate
Enqueue lazy-pushed jobs that have accumulated from JobQueueGroup.
Definition: JobQueueEnqueueUpdate.php:33
MergeableUpdate
Interface that deferrable updates can implement to signal that updates can be combined.
Definition: MergeableUpdate.php:21
MWExceptionHandler\logException
static logException(Throwable $e, $catcher=self::CAUGHT_BY_OTHER, $extraData=[])
Log a throwable to the exception log (if enabled).
Definition: MWExceptionHandler.php:700
JobQueueEnqueueUpdate\__construct
__construct(string $domain, array $jobs)
Definition: JobQueueEnqueueUpdate.php:44
MediaWiki\JobQueue\JobQueueGroupFactory
Class to construct JobQueueGroups.
Definition: JobQueueGroupFactory.php:37
JobQueueEnqueueUpdate\merge
merge(MergeableUpdate $update)
Merge this enqueued update with a new MergeableUpdate of the same qualified class name....
Definition: JobQueueEnqueueUpdate.php:51
DeferrableUpdate
Interface that deferrable updates should implement.
Definition: DeferrableUpdate.php:11
JobQueueEnqueueUpdate\$jobsByDomain
IJobSpecification[][] $jobsByDomain
Definition: JobQueueEnqueueUpdate.php:35
IJobSpecification
Interface for serializable objects that describe a job queue task.
Definition: IJobSpecification.php:42