2012-08-29 00:01:31 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
2021-03-17 12:37:06 +00:00
|
|
|
|
2023-11-21 21:08:14 +00:00
|
|
|
use MediaWiki\Deferred\DeferredUpdates;
|
|
|
|
|
use MediaWiki\Deferred\JobQueueEnqueueUpdate;
|
2024-06-05 18:44:20 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-09-11 18:39:11 +00:00
|
|
|
use Wikimedia\Rdbms\ReadOnlyMode;
|
2021-03-17 12:37:06 +00:00
|
|
|
use Wikimedia\UUID\GlobalIdGenerator;
|
2012-08-29 00:01:31 +00:00
|
|
|
|
|
|
|
|
/**
|
2022-05-19 06:45:26 +00:00
|
|
|
* Handle enqueueing of background jobs.
|
2012-08-29 00:01:31 +00:00
|
|
|
*
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
* @warning This service class supports queuing jobs to foreign wikis via JobQueueGroupFactory,
|
|
|
|
|
* but other operations may be called for the local wiki only. Exceptions may be thrown if you
|
|
|
|
|
* attempt to inspect, pop, or execute a foreign wiki's job queue.
|
|
|
|
|
*
|
2012-11-06 00:43:44 +00:00
|
|
|
* @since 1.21
|
2024-03-25 22:00:38 +00:00
|
|
|
* @ingroup JobQueue
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
|
|
|
|
class JobQueueGroup {
|
2019-06-05 18:32:05 +00:00
|
|
|
/** @var MapCacheLRU */
|
2013-01-14 22:06:11 +00:00
|
|
|
protected $cache;
|
|
|
|
|
|
2018-10-13 07:29:23 +00:00
|
|
|
/** @var string Wiki domain ID */
|
|
|
|
|
protected $domain;
|
2023-09-11 18:39:11 +00:00
|
|
|
/** @var ReadOnlyMode Read only mode */
|
2021-03-17 12:37:06 +00:00
|
|
|
protected $readOnlyMode;
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
/** @var array|null */
|
|
|
|
|
private $localJobClasses;
|
2021-03-17 12:37:06 +00:00
|
|
|
/** @var array */
|
|
|
|
|
private $jobTypeConfiguration;
|
|
|
|
|
/** @var array */
|
|
|
|
|
private $jobTypesExcludedFromDefaultQueue;
|
|
|
|
|
/** @var IBufferingStatsdDataFactory */
|
|
|
|
|
private $statsdDataFactory;
|
|
|
|
|
/** @var WANObjectCache */
|
|
|
|
|
private $wanCache;
|
|
|
|
|
/** @var GlobalIdGenerator */
|
|
|
|
|
private $globalIdGenerator;
|
2012-08-29 00:01:31 +00:00
|
|
|
|
2013-07-04 07:05:19 +00:00
|
|
|
/** @var array Map of (bucket => (queue => JobQueue, types => list of types) */
|
|
|
|
|
protected $coalescedQueues;
|
|
|
|
|
|
2020-05-12 22:37:45 +00:00
|
|
|
public const TYPE_DEFAULT = 1; // integer; jobs popped by default
|
|
|
|
|
private const TYPE_ANY = 2; // integer; any job
|
2012-08-29 00:01:31 +00:00
|
|
|
|
2020-05-12 22:37:45 +00:00
|
|
|
public const USE_CACHE = 1; // integer; use process or persistent cache
|
2013-01-14 22:06:11 +00:00
|
|
|
|
2020-05-12 22:37:45 +00:00
|
|
|
private const PROC_CACHE_TTL = 15; // integer; seconds
|
2013-01-14 22:06:11 +00:00
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
2021-03-17 12:37:06 +00:00
|
|
|
* @internal Use MediaWikiServices::getJobQueueGroupFactory
|
|
|
|
|
*
|
2018-10-13 07:29:23 +00:00
|
|
|
* @param string $domain Wiki domain ID
|
2023-09-11 18:39:11 +00:00
|
|
|
* @param ReadOnlyMode $readOnlyMode Read-only mode
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
* @param array|null $localJobClasses
|
2021-03-17 12:37:06 +00:00
|
|
|
* @param array $jobTypeConfiguration
|
|
|
|
|
* @param array $jobTypesExcludedFromDefaultQueue
|
|
|
|
|
* @param IBufferingStatsdDataFactory $statsdDataFactory
|
|
|
|
|
* @param WANObjectCache $wanCache
|
|
|
|
|
* @param GlobalIdGenerator $globalIdGenerator
|
2024-06-05 18:44:20 +00:00
|
|
|
*
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
2021-03-17 12:37:06 +00:00
|
|
|
public function __construct(
|
|
|
|
|
$domain,
|
2023-09-11 18:39:11 +00:00
|
|
|
ReadOnlyMode $readOnlyMode,
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
?array $localJobClasses,
|
2021-03-17 12:37:06 +00:00
|
|
|
array $jobTypeConfiguration,
|
|
|
|
|
array $jobTypesExcludedFromDefaultQueue,
|
|
|
|
|
IBufferingStatsdDataFactory $statsdDataFactory,
|
|
|
|
|
WANObjectCache $wanCache,
|
|
|
|
|
GlobalIdGenerator $globalIdGenerator
|
|
|
|
|
) {
|
2018-10-13 07:29:23 +00:00
|
|
|
$this->domain = $domain;
|
2021-03-17 12:37:06 +00:00
|
|
|
$this->readOnlyMode = $readOnlyMode;
|
2018-07-11 12:54:51 +00:00
|
|
|
$this->cache = new MapCacheLRU( 10 );
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
$this->localJobClasses = $localJobClasses;
|
2021-03-17 12:37:06 +00:00
|
|
|
$this->jobTypeConfiguration = $jobTypeConfiguration;
|
|
|
|
|
$this->jobTypesExcludedFromDefaultQueue = $jobTypesExcludedFromDefaultQueue;
|
|
|
|
|
$this->statsdDataFactory = $statsdDataFactory;
|
|
|
|
|
$this->wanCache = $wanCache;
|
|
|
|
|
$this->globalIdGenerator = $globalIdGenerator;
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-02-21 19:45:51 +00:00
|
|
|
* Get the job queue object for a given queue type
|
|
|
|
|
*
|
2013-11-25 17:12:42 +00:00
|
|
|
* @param string $type
|
2013-02-21 19:45:51 +00:00
|
|
|
* @return JobQueue
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
|
|
|
|
public function get( $type ) {
|
2018-10-13 07:29:23 +00:00
|
|
|
$conf = [ 'domain' => $this->domain, 'type' => $type ];
|
2022-04-04 09:57:04 +00:00
|
|
|
$conf += $this->jobTypeConfiguration[$type] ?? $this->jobTypeConfiguration['default'];
|
2018-07-19 16:13:38 +00:00
|
|
|
if ( !isset( $conf['readOnlyReason'] ) ) {
|
2023-09-11 18:39:11 +00:00
|
|
|
$conf['readOnlyReason'] = $this->readOnlyMode->getConfiguredReason();
|
2016-03-25 19:52:39 +00:00
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
|
2021-03-17 12:37:06 +00:00
|
|
|
$conf['stats'] = $this->statsdDataFactory;
|
|
|
|
|
$conf['wanCache'] = $this->wanCache;
|
|
|
|
|
$conf['idGenerator'] = $this->globalIdGenerator;
|
2019-03-30 04:41:34 +00:00
|
|
|
|
2012-10-24 17:14:54 +00:00
|
|
|
return JobQueue::factory( $conf );
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-05-15 23:23:51 +00:00
|
|
|
* Insert jobs into the respective queues of which they belong
|
2013-02-21 19:45:51 +00:00
|
|
|
*
|
|
|
|
|
* This inserts the jobs into the queue specified by $wgJobTypeConf
|
|
|
|
|
* and updates the aggregate job queue information cache as needed.
|
2012-08-29 00:01:31 +00:00
|
|
|
*
|
2015-05-15 23:23:51 +00:00
|
|
|
* @param IJobSpecification|IJobSpecification[] $jobs A single Job or a list of Jobs
|
2014-04-16 18:07:26 +00:00
|
|
|
* @return void
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
|
|
|
|
public function push( $jobs ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
|
2019-01-09 16:24:36 +00:00
|
|
|
if ( $jobs === [] ) {
|
2014-04-16 18:07:26 +00:00
|
|
|
return;
|
2013-11-19 00:12:12 +00:00
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
|
2015-05-15 23:23:51 +00:00
|
|
|
$this->assertValidJobs( $jobs );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$jobsByType = []; // (job type => list of jobs)
|
2012-08-29 00:01:31 +00:00
|
|
|
foreach ( $jobs as $job ) {
|
2021-09-29 21:03:50 +00:00
|
|
|
$type = $job->getType();
|
|
|
|
|
if ( isset( $this->jobTypeConfiguration[$type] ) ) {
|
|
|
|
|
$jobsByType[$type][] = $job;
|
|
|
|
|
} else {
|
|
|
|
|
if (
|
|
|
|
|
isset( $this->jobTypeConfiguration['default']['typeAgnostic'] ) &&
|
|
|
|
|
$this->jobTypeConfiguration['default']['typeAgnostic']
|
|
|
|
|
) {
|
|
|
|
|
$jobsByType['default'][] = $job;
|
|
|
|
|
} else {
|
|
|
|
|
$jobsByType[$type][] = $job;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $jobsByType as $type => $jobs ) {
|
2014-04-16 17:51:11 +00:00
|
|
|
$this->get( $type )->push( $jobs );
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-11 12:54:51 +00:00
|
|
|
if ( $this->cache->hasField( 'queues-ready', 'list' ) ) {
|
|
|
|
|
$list = $this->cache->getField( 'queues-ready', 'list' );
|
2013-01-14 22:06:11 +00:00
|
|
|
if ( count( array_diff( array_keys( $jobsByType ), $list ) ) ) {
|
|
|
|
|
$this->cache->clear( 'queues-ready' );
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-11 11:57:12 +00:00
|
|
|
|
2024-06-05 18:44:20 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance();
|
2016-09-11 11:57:12 +00:00
|
|
|
$cache->set(
|
2018-10-13 07:29:23 +00:00
|
|
|
$cache->makeGlobalKey( 'jobqueue', $this->domain, 'hasjobs', self::TYPE_ANY ),
|
2016-09-11 11:57:12 +00:00
|
|
|
'true',
|
|
|
|
|
15
|
|
|
|
|
);
|
2021-03-17 12:37:06 +00:00
|
|
|
if ( array_diff( array_keys( $jobsByType ), $this->jobTypesExcludedFromDefaultQueue ) ) {
|
2016-09-11 11:57:12 +00:00
|
|
|
$cache->set(
|
2018-10-13 07:29:23 +00:00
|
|
|
$cache->makeGlobalKey( 'jobqueue', $this->domain, 'hasjobs', self::TYPE_DEFAULT ),
|
2016-09-11 11:57:12 +00:00
|
|
|
'true',
|
|
|
|
|
15
|
|
|
|
|
);
|
|
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-15 23:23:51 +00:00
|
|
|
/**
|
|
|
|
|
* Buffer jobs for insertion via push() or call it now if in CLI mode
|
|
|
|
|
*
|
|
|
|
|
* @param IJobSpecification|IJobSpecification[] $jobs A single Job or a list of Jobs
|
|
|
|
|
* @return void
|
|
|
|
|
* @since 1.26
|
|
|
|
|
*/
|
|
|
|
|
public function lazyPush( $jobs ) {
|
2017-04-10 11:32:15 +00:00
|
|
|
if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
|
2015-05-15 23:23:51 +00:00
|
|
|
$this->push( $jobs );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
|
2015-05-15 23:23:51 +00:00
|
|
|
|
|
|
|
|
// Throw errors now instead of on push(), when other jobs may be buffered
|
|
|
|
|
$this->assertValidJobs( $jobs );
|
|
|
|
|
|
2018-10-13 07:29:23 +00:00
|
|
|
DeferredUpdates::addUpdate( new JobQueueEnqueueUpdate( $this->domain, $jobs ) );
|
2015-05-15 23:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
* Pop one job off a job queue
|
|
|
|
|
*
|
|
|
|
|
* @warning May not be called on foreign wikis!
|
2012-08-29 00:01:31 +00:00
|
|
|
*
|
2013-02-21 19:45:51 +00:00
|
|
|
* This pops a job off a queue as specified by $wgJobTypeConf and
|
|
|
|
|
* updates the aggregate job queue information cache as needed.
|
|
|
|
|
*
|
2013-12-21 20:57:45 +00:00
|
|
|
* @param int|string $qtype JobQueueGroup::TYPE_* constant or job type string
|
2013-11-25 17:12:42 +00:00
|
|
|
* @param int $flags Bitfield of JobQueueGroup::USE_* constants
|
2021-03-19 16:12:50 +00:00
|
|
|
* @param array $ignored List of job types to ignore
|
2022-07-31 00:02:18 +00:00
|
|
|
* @return RunnableJob|false Returns false on failure
|
2023-07-11 09:02:03 +00:00
|
|
|
* @throws JobQueueError
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
2021-03-19 16:12:50 +00:00
|
|
|
public function pop( $qtype = self::TYPE_DEFAULT, $flags = 0, array $ignored = [] ) {
|
2013-12-21 20:57:45 +00:00
|
|
|
$job = false;
|
|
|
|
|
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
if ( !$this->localJobClasses ) {
|
2019-03-30 04:41:34 +00:00
|
|
|
throw new JobQueueError(
|
|
|
|
|
"Cannot pop '{$qtype}' job off foreign '{$this->domain}' wiki queue." );
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
}
|
|
|
|
|
if ( is_string( $qtype ) && !isset( $this->localJobClasses[$qtype] ) ) {
|
2019-03-30 04:41:34 +00:00
|
|
|
// Do not pop jobs if there is no class for the queue type
|
|
|
|
|
throw new JobQueueError( "Unrecognized job type '$qtype'." );
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-05 20:00:24 +00:00
|
|
|
if ( is_string( $qtype ) ) { // specific job type
|
2021-03-19 16:12:50 +00:00
|
|
|
if ( !in_array( $qtype, $ignored ) ) {
|
2013-12-21 20:57:45 +00:00
|
|
|
$job = $this->get( $qtype )->pop();
|
2013-02-05 20:00:24 +00:00
|
|
|
}
|
|
|
|
|
} else { // any job in the "default" jobs types
|
|
|
|
|
if ( $flags & self::USE_CACHE ) {
|
2018-07-11 12:54:51 +00:00
|
|
|
if ( !$this->cache->hasField( 'queues-ready', 'list', self::PROC_CACHE_TTL ) ) {
|
|
|
|
|
$this->cache->setField( 'queues-ready', 'list', $this->getQueuesWithJobs() );
|
2013-02-05 20:00:24 +00:00
|
|
|
}
|
2018-07-11 12:54:51 +00:00
|
|
|
$types = $this->cache->getField( 'queues-ready', 'list' );
|
2013-02-05 20:00:24 +00:00
|
|
|
} else {
|
|
|
|
|
$types = $this->getQueuesWithJobs();
|
2013-01-14 22:06:11 +00:00
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
|
2013-02-05 20:00:24 +00:00
|
|
|
if ( $qtype == self::TYPE_DEFAULT ) {
|
|
|
|
|
$types = array_intersect( $types, $this->getDefaultQueueTypes() );
|
|
|
|
|
}
|
2013-12-21 20:57:45 +00:00
|
|
|
|
2021-03-19 16:12:50 +00:00
|
|
|
$types = array_diff( $types, $ignored ); // avoid selected types
|
2013-02-05 20:00:24 +00:00
|
|
|
shuffle( $types ); // avoid starvation
|
|
|
|
|
|
|
|
|
|
foreach ( $types as $type ) { // for each queue...
|
|
|
|
|
$job = $this->get( $type )->pop();
|
|
|
|
|
if ( $job ) { // found
|
2013-12-21 20:57:45 +00:00
|
|
|
break;
|
2013-02-05 20:00:24 +00:00
|
|
|
} else { // not found
|
|
|
|
|
$this->cache->clear( 'queues-ready' );
|
|
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
2013-02-05 20:00:24 +00:00
|
|
|
}
|
2013-12-21 20:57:45 +00:00
|
|
|
|
|
|
|
|
return $job;
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Acknowledge that a job was completed
|
|
|
|
|
*
|
2019-07-05 20:20:56 +00:00
|
|
|
* @param RunnableJob $job
|
2015-05-15 23:23:51 +00:00
|
|
|
* @return void
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
2019-07-05 20:20:56 +00:00
|
|
|
public function ack( RunnableJob $job ) {
|
2015-05-15 23:23:51 +00:00
|
|
|
$this->get( $job->getType() )->ack( $job );
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-08 22:01:40 +00:00
|
|
|
/**
|
|
|
|
|
* Register the "root job" of a given job into the queue for de-duplication.
|
|
|
|
|
* This should only be called right *after* all the new jobs have been inserted.
|
|
|
|
|
*
|
2022-05-19 06:45:26 +00:00
|
|
|
* @deprecated since 1.40
|
2019-07-05 20:20:56 +00:00
|
|
|
* @param RunnableJob $job
|
2012-11-08 22:01:40 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-07-05 20:20:56 +00:00
|
|
|
public function deduplicateRootJob( RunnableJob $job ) {
|
2022-05-19 06:45:26 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.40' );
|
|
|
|
|
return true;
|
2012-11-08 22:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-12 01:56:16 +00:00
|
|
|
/**
|
2016-09-05 20:21:26 +00:00
|
|
|
* Wait for any replica DBs or backup queue servers to catch up.
|
2013-03-12 01:56:16 +00:00
|
|
|
*
|
|
|
|
|
* This does nothing for certain queue classes.
|
|
|
|
|
*
|
2023-08-24 11:50:57 +00:00
|
|
|
* @deprecated since 1.41, use JobQueue::waitForBackups() instead.
|
|
|
|
|
*
|
2013-03-12 01:56:16 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function waitForBackups() {
|
2023-08-24 11:50:57 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.41' );
|
2013-03-12 01:56:16 +00:00
|
|
|
// Try to avoid doing this more than once per queue storage medium
|
2021-03-17 12:37:06 +00:00
|
|
|
foreach ( $this->jobTypeConfiguration as $type => $conf ) {
|
2013-03-12 01:56:16 +00:00
|
|
|
$this->get( $type )->waitForBackups();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* Get the list of queue types
|
|
|
|
|
*
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
* @warning May not be called on foreign wikis!
|
|
|
|
|
*
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return string[]
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
|
|
|
|
public function getQueueTypes() {
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
if ( !$this->localJobClasses ) {
|
|
|
|
|
throw new JobQueueError( 'Cannot inspect job queue from foreign wiki' );
|
|
|
|
|
}
|
|
|
|
|
return array_keys( $this->localJobClasses );
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the list of default queue types
|
|
|
|
|
*
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
* @warning May not be called on foreign wikis!
|
|
|
|
|
*
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return string[]
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
|
|
|
|
public function getDefaultQueueTypes() {
|
2021-03-17 12:37:06 +00:00
|
|
|
return array_diff( $this->getQueueTypes(), $this->jobTypesExcludedFromDefaultQueue );
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
2012-11-03 00:31:25 +00:00
|
|
|
|
2014-04-08 16:34:49 +00:00
|
|
|
/**
|
|
|
|
|
* Check if there are any queues with jobs (this is cached)
|
|
|
|
|
*
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
* @warning May not be called on foreign wikis!
|
|
|
|
|
*
|
|
|
|
|
* @since 1.23
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param int $type JobQueueGroup::TYPE_* constant
|
2014-04-08 16:34:49 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function queuesHaveJobs( $type = self::TYPE_ANY ) {
|
2024-06-05 18:44:20 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance();
|
2018-10-13 07:29:23 +00:00
|
|
|
$key = $cache->makeGlobalKey( 'jobqueue', $this->domain, 'hasjobs', $type );
|
2014-04-08 16:34:49 +00:00
|
|
|
|
2015-10-26 07:41:05 +00:00
|
|
|
$value = $cache->get( $key );
|
2014-04-08 16:34:49 +00:00
|
|
|
if ( $value === false ) {
|
|
|
|
|
$queues = $this->getQueuesWithJobs();
|
|
|
|
|
if ( $type == self::TYPE_DEFAULT ) {
|
|
|
|
|
$queues = array_intersect( $queues, $this->getDefaultQueueTypes() );
|
|
|
|
|
}
|
|
|
|
|
$value = count( $queues ) ? 'true' : 'false';
|
2015-10-26 07:41:05 +00:00
|
|
|
$cache->add( $key, $value, 15 );
|
2014-04-08 16:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ( $value === 'true' );
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-03 00:31:25 +00:00
|
|
|
/**
|
2013-02-05 20:00:24 +00:00
|
|
|
* Get the list of job types that have non-empty queues
|
|
|
|
|
*
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
* @warning May not be called on foreign wikis!
|
|
|
|
|
*
|
2019-03-30 04:11:35 +00:00
|
|
|
* @return string[] List of job types that have non-empty queues
|
2012-11-03 00:31:25 +00:00
|
|
|
*/
|
|
|
|
|
public function getQueuesWithJobs() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$types = [];
|
2013-07-04 07:05:19 +00:00
|
|
|
foreach ( $this->getCoalescedQueues() as $info ) {
|
2019-03-30 04:11:35 +00:00
|
|
|
/** @var JobQueue $queue */
|
|
|
|
|
$queue = $info['queue'];
|
|
|
|
|
$nonEmpty = $queue->getSiblingQueuesWithJobs( $this->getQueueTypes() );
|
2013-07-04 07:05:19 +00:00
|
|
|
if ( is_array( $nonEmpty ) ) { // batching features supported
|
|
|
|
|
$types = array_merge( $types, $nonEmpty );
|
|
|
|
|
} else { // we have to go through the queues in the bucket one-by-one
|
|
|
|
|
foreach ( $info['types'] as $type ) {
|
|
|
|
|
if ( !$this->get( $type )->isEmpty() ) {
|
|
|
|
|
$types[] = $type;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-03 00:31:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-11-25 14:38:37 +00:00
|
|
|
|
2012-11-03 00:31:25 +00:00
|
|
|
return $types;
|
|
|
|
|
}
|
2013-01-14 22:06:11 +00:00
|
|
|
|
2013-07-04 07:05:19 +00:00
|
|
|
/**
|
2020-04-09 06:53:40 +00:00
|
|
|
* Get the size of the queues for a list of job types
|
2013-07-04 07:05:19 +00:00
|
|
|
*
|
jobqueue: Disallow cross-wiki JobQueueGroup calls that require JobClasses
=== Change ===
Follows-up Ia61e00d6dc98c20650 which moved injection of $wgJobClasses
from happening lazily in methods that are never called in any
production code, to happen unconditionally when any JobQueueGroup
is constructed and injected, which happens a lot nowadays given that
most code is now dependency-injected.
For example, when logging in, CentralAuth can call into services
for getUserGroupManager( $wikiID )->getUserGroupMemberships() which
merely performs a simple database select query. But, because this
service class does contain other methods that can queue a job, this
config now needs to be computed across wikis via a potentially slow
shell execution even in simple GET requests.
One way to solve this, which brings back the previous state, is to
keep this logically dependency-injected but deferred by wrapping it
in a closure. We could inject `callable $getJobClassesFn` as param
from JobQueueGroupFactory to JobQueueGroup.
However, given that $wgConf->getConfig() was broken in production
for two weeks and there is not 1 log entry in Logstash during this
time, I think that means these methods are actually never called.
Hence, I'm instead going in the opposite direction of extending the
restriction of pop() to these other methods as well.
Thus, we reduce JobQueueGroup support for cross-wiki method calls
to get(), push() and lazyPush().
=== History ===
The natural question is, why was this added, and do we know that
this reason no longer applies? The getConfig() call was introduced
in 2013 with commit 04e0d75f86b (I7e6904ead1). This mentions as
reasoning to support maintenance/nextJobDB.php, which was was removed
in commit ce2ae144e62 (Ia74386c650) a year later.
It looks like this script supported only JobQueueDB, as used by
a WMF-specific jobrunner known as "jobs-loop.sh", which predates
WMF's JobQueue migration from MySQL to Redis, and later to Kafka,
as per
<https://wikitech.wikimedia.org/wiki/History_of_job_queue_runners_at_WMF>
Bug: T344223
Bug: T343291
Change-Id: Ic2293c4b4be10a698a2f891eaa63c1de7383f982
2023-08-15 17:50:49 +00:00
|
|
|
* @warning May not be called on foreign wikis!
|
|
|
|
|
*
|
2019-03-30 04:11:35 +00:00
|
|
|
* @return int[] Map of (job type => size)
|
2013-07-04 07:05:19 +00:00
|
|
|
*/
|
|
|
|
|
public function getQueueSizes() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$sizeMap = [];
|
2013-07-04 07:05:19 +00:00
|
|
|
foreach ( $this->getCoalescedQueues() as $info ) {
|
2019-03-30 04:11:35 +00:00
|
|
|
/** @var JobQueue $queue */
|
|
|
|
|
$queue = $info['queue'];
|
|
|
|
|
$sizes = $queue->getSiblingQueueSizes( $this->getQueueTypes() );
|
2013-07-04 07:05:19 +00:00
|
|
|
if ( is_array( $sizes ) ) { // batching features supported
|
2020-07-31 19:41:28 +00:00
|
|
|
$sizeMap += $sizes;
|
2013-07-04 07:05:19 +00:00
|
|
|
} else { // we have to go through the queues in the bucket one-by-one
|
|
|
|
|
foreach ( $info['types'] as $type ) {
|
|
|
|
|
$sizeMap[$type] = $this->get( $type )->getSize();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-25 14:38:37 +00:00
|
|
|
|
2013-07-04 07:05:19 +00:00
|
|
|
return $sizeMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-30 17:56:27 +00:00
|
|
|
* @return array[]
|
|
|
|
|
* @phan-return array<string,array{queue:JobQueue,types:array<string,class-string>}>
|
2013-07-04 07:05:19 +00:00
|
|
|
*/
|
|
|
|
|
protected function getCoalescedQueues() {
|
|
|
|
|
if ( $this->coalescedQueues === null ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->coalescedQueues = [];
|
2021-03-17 12:37:06 +00:00
|
|
|
foreach ( $this->jobTypeConfiguration as $type => $conf ) {
|
|
|
|
|
$conf['domain'] = $this->domain;
|
|
|
|
|
$conf['type'] = 'null';
|
|
|
|
|
$conf['stats'] = $this->statsdDataFactory;
|
|
|
|
|
$conf['wanCache'] = $this->wanCache;
|
|
|
|
|
$conf['idGenerator'] = $this->globalIdGenerator;
|
|
|
|
|
|
|
|
|
|
$queue = JobQueue::factory( $conf );
|
2013-07-04 07:05:19 +00:00
|
|
|
$loc = $queue->getCoalesceLocationInternal();
|
|
|
|
|
if ( !isset( $this->coalescedQueues[$loc] ) ) {
|
|
|
|
|
$this->coalescedQueues[$loc]['queue'] = $queue;
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->coalescedQueues[$loc]['types'] = [];
|
2013-07-04 07:05:19 +00:00
|
|
|
}
|
|
|
|
|
if ( $type === 'default' ) {
|
|
|
|
|
$this->coalescedQueues[$loc]['types'] = array_merge(
|
|
|
|
|
$this->coalescedQueues[$loc]['types'],
|
2021-03-17 12:37:06 +00:00
|
|
|
array_diff( $this->getQueueTypes(), array_keys( $this->jobTypeConfiguration ) )
|
2013-07-04 07:05:19 +00:00
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$this->coalescedQueues[$loc]['types'][] = $type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->coalescedQueues;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-15 23:23:51 +00:00
|
|
|
/**
|
|
|
|
|
* @param array $jobs
|
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
|
*/
|
|
|
|
|
private function assertValidJobs( array $jobs ) {
|
2021-11-19 23:19:42 +00:00
|
|
|
foreach ( $jobs as $job ) {
|
2015-05-15 23:23:51 +00:00
|
|
|
if ( !( $job instanceof IJobSpecification ) ) {
|
2024-07-31 16:47:01 +00:00
|
|
|
$type = get_debug_type( $job );
|
2021-08-19 20:00:32 +00:00
|
|
|
throw new InvalidArgumentException( "Expected IJobSpecification objects, got " . $type );
|
2015-05-15 23:23:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|