Debian Codegraph @

includes/deferred/JobQueueEnqueueUpdate.php

raw symbols SCIP
1 <?php
2 /**
3 * Handler for triggering the enqueuing of lazy-pushed jobs
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 namespace MediaWiki\Deferred;
24
25 use IJobSpecification;
26 use MediaWiki\JobQueue\JobQueueGroupFactory;
27 use MediaWiki\MediaWikiServices;
28 use MWExceptionHandler;
29 use Throwable;
30 use Wikimedia\Assert\Assert;
31
32 /**
33 * Enqueue lazy-pushed jobs that have accumulated from JobQueueGroup
34 *
35 * @ingroup JobQueue
36 * @since 1.33
37 */
38 class JobQueueEnqueueUpdate implements DeferrableUpdate, MergeableUpdate {
39 /** @var IJobSpecification[][] */
40 private $jobsByDomain;
41
42 /** @var JobQueueGroupFactory */
43 private $jobQueueGroupFactory;
44
45 /**
46 * @param string $domain DB domain ID
47 * @param IJobSpecification[] $jobs
48 */
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
55 /** @inheritDoc */
56 public function merge( MergeableUpdate $update ) {
57 /** @var self $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
69 /** @inheritDoc */
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
83 /** @deprecated class alias since 1.42 */
84 class_alias( JobQueueEnqueueUpdate::class, 'JobQueueEnqueueUpdate' );