Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| JobQueueEnqueueUpdate | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| merge | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| doUpdate | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Handler for triggering the enqueuing of lazy-pushed jobs |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Deferred; |
| 10 | |
| 11 | use MediaWiki\Exception\MWExceptionHandler; |
| 12 | use MediaWiki\JobQueue\IJobSpecification; |
| 13 | use MediaWiki\JobQueue\JobQueueGroupFactory; |
| 14 | use MediaWiki\MediaWikiServices; |
| 15 | use Throwable; |
| 16 | use Wikimedia\Assert\Assert; |
| 17 | |
| 18 | /** |
| 19 | * Enqueue lazy-pushed jobs that have accumulated from JobQueueGroup |
| 20 | * |
| 21 | * @ingroup JobQueue |
| 22 | * @since 1.33 |
| 23 | */ |
| 24 | class JobQueueEnqueueUpdate implements DeferrableUpdate, MergeableUpdate { |
| 25 | /** @var IJobSpecification[][] */ |
| 26 | private $jobsByDomain; |
| 27 | |
| 28 | /** @var JobQueueGroupFactory */ |
| 29 | private $jobQueueGroupFactory; |
| 30 | |
| 31 | /** |
| 32 | * @param string $domain DB domain ID |
| 33 | * @param IJobSpecification[] $jobs |
| 34 | */ |
| 35 | public function __construct( string $domain, array $jobs ) { |
| 36 | $this->jobsByDomain[$domain] = $jobs; |
| 37 | // TODO Inject services, when DeferredUpdates supports DI |
| 38 | $this->jobQueueGroupFactory = MediaWikiServices::getInstance()->getJobQueueGroupFactory(); |
| 39 | } |
| 40 | |
| 41 | /** @inheritDoc */ |
| 42 | public function merge( MergeableUpdate $update ) { |
| 43 | /** @var self $update */ |
| 44 | Assert::parameterType( __CLASS__, $update, '$update' ); |
| 45 | '@phan-var self $update'; |
| 46 | |
| 47 | foreach ( $update->jobsByDomain as $domain => $jobs ) { |
| 48 | $this->jobsByDomain[$domain] = array_merge( |
| 49 | $this->jobsByDomain[$domain] ?? [], |
| 50 | $jobs |
| 51 | ); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** @inheritDoc */ |
| 56 | public function doUpdate() { |
| 57 | foreach ( $this->jobsByDomain as $domain => $jobs ) { |
| 58 | $group = $this->jobQueueGroupFactory->makeJobQueueGroup( $domain ); |
| 59 | try { |
| 60 | $group->push( $jobs ); |
| 61 | } catch ( Throwable $e ) { |
| 62 | // Get in as many jobs as possible and let other post-send updates happen |
| 63 | MWExceptionHandler::logException( $e ); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /** @deprecated class alias since 1.42 */ |
| 70 | class_alias( JobQueueEnqueueUpdate::class, 'JobQueueEnqueueUpdate' ); |