MediaWiki master
JobQueueEnqueueUpdate.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Deferred;
24
29use Throwable;
30use Wikimedia\Assert\Assert;
31
40 private $jobsByDomain;
41
43 private $jobQueueGroupFactory;
44
49 public function __construct( string $domain, array $jobs ) {
50 $this->jobsByDomain[$domain] = $jobs;
51 // TODO Inject services, when DeferredUpdates supports DI
52 $this->jobQueueGroupFactory = MediaWikiServices::getInstance()->getJobQueueGroupFactory();
53 }
54
56 public function merge( MergeableUpdate $update ) {
58 Assert::parameterType( __CLASS__, $update, '$update' );
59 '@phan-var self $update';
60
61 foreach ( $update->jobsByDomain as $domain => $jobs ) {
62 $this->jobsByDomain[$domain] = array_merge(
63 $this->jobsByDomain[$domain] ?? [],
64 $jobs
65 );
66 }
67 }
68
70 public function doUpdate() {
71 foreach ( $this->jobsByDomain as $domain => $jobs ) {
72 $group = $this->jobQueueGroupFactory->makeJobQueueGroup( $domain );
73 try {
74 $group->push( $jobs );
75 } catch ( Throwable $e ) {
76 // Get in as many jobs as possible and let other post-send updates happen
77 MWExceptionHandler::logException( $e );
78 }
79 }
80 }
81}
82
84class_alias( JobQueueEnqueueUpdate::class, 'JobQueueEnqueueUpdate' );
Handler class for MWExceptions.
Enqueue lazy-pushed jobs that have accumulated from JobQueueGroup.
merge(MergeableUpdate $update)
Merge this enqueued update with a new MergeableUpdate of the same qualified class name.
Factory for JobQueueGroup objects.
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Interface for serializable objects that describe a job queue task.
Interface that deferrable updates should implement.
Interface that deferrable updates can implement to signal that updates can be combined.