2006-04-19 21:13:47 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2009-08-02 19:35:17 +00:00
|
|
|
* 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
|
|
|
|
|
*
|
2012-09-02 18:33:22 +00:00
|
|
|
* @file
|
2006-04-19 21:13:47 +00:00
|
|
|
*/
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2006-04-19 21:20:03 +00:00
|
|
|
|
2012-09-02 18:33:22 +00:00
|
|
|
/**
|
2022-09-23 15:10:58 +00:00
|
|
|
* Report number of jobs currently waiting in primary database.
|
|
|
|
|
*
|
|
|
|
|
* Based on runJobs.php. Note that this only works for JobQueue backends
|
|
|
|
|
* that implement JobQueue::doGetSize. Implementations based on Kafka,
|
|
|
|
|
* for example, might not have a way to obtain this. In that case,
|
|
|
|
|
* telemetry should be provided externally, e.g. with Grafana/Prometheus.
|
2012-09-02 18:33:22 +00:00
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
2022-09-23 15:10:58 +00:00
|
|
|
* @author Tim Starling
|
|
|
|
|
* @author Antoine Musso
|
2012-09-02 18:33:22 +00:00
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class ShowJobs extends Maintenance {
|
2024-09-11 20:54:17 +00:00
|
|
|
private const STATE_METHODS = [
|
2015-08-25 08:17:43 +00:00
|
|
|
'unclaimed' => 'getAllQueuedJobs',
|
|
|
|
|
'delayed' => 'getAllDelayedJobs',
|
|
|
|
|
'claimed' => 'getAllAcquiredJobs',
|
|
|
|
|
'abandoned' => 'getAllAbandonedJobs',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2015-08-25 08:17:43 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2021-05-14 20:04:02 +00:00
|
|
|
$this->addDescription( 'Show number of jobs waiting in primary database' );
|
2009-08-14 11:15:47 +00:00
|
|
|
$this->addOption( 'group', 'Show number of jobs per job type' );
|
2015-08-25 08:17:43 +00:00
|
|
|
$this->addOption( 'list', 'Show a list of all jobs instead of counts' );
|
2014-10-08 20:39:09 +00:00
|
|
|
$this->addOption( 'type', 'Only show/count jobs of a given type', false, true );
|
2015-08-25 08:17:43 +00:00
|
|
|
$this->addOption( 'status', 'Filter list by state (unclaimed,delayed,claimed,abandoned)' );
|
|
|
|
|
$this->addOption( 'limit', 'Limit of jobs listed' );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2012-12-14 18:47:06 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
2015-08-25 08:17:43 +00:00
|
|
|
$typeFilter = $this->getOption( 'type', '' );
|
|
|
|
|
$stateFilter = $this->getOption( 'status', '' );
|
|
|
|
|
$stateLimit = (float)$this->getOption( 'limit', INF );
|
|
|
|
|
|
2023-08-31 09:21:12 +00:00
|
|
|
$group = $this->getServiceContainer()->getJobQueueGroup();
|
2015-08-25 08:17:43 +00:00
|
|
|
|
|
|
|
|
$filteredTypes = $typeFilter
|
2016-02-17 09:09:32 +00:00
|
|
|
? [ $typeFilter ]
|
2015-08-25 08:17:43 +00:00
|
|
|
: $group->getQueueTypes();
|
|
|
|
|
$filteredStates = $stateFilter
|
2024-09-11 20:54:17 +00:00
|
|
|
? array_intersect_key( self::STATE_METHODS, [ $stateFilter => 1 ] )
|
|
|
|
|
: self::STATE_METHODS;
|
2015-08-25 08:17:43 +00:00
|
|
|
|
2013-07-10 00:15:26 +00:00
|
|
|
if ( $this->hasOption( 'list' ) ) {
|
2015-08-25 08:17:43 +00:00
|
|
|
$count = 0;
|
|
|
|
|
foreach ( $filteredTypes as $type ) {
|
2013-07-10 00:15:26 +00:00
|
|
|
$queue = $group->get( $type );
|
2015-08-25 08:17:43 +00:00
|
|
|
foreach ( $filteredStates as $state => $method ) {
|
|
|
|
|
foreach ( $queue->$method() as $job ) {
|
|
|
|
|
/** @var Job $job */
|
|
|
|
|
$this->output( $job->toString() . " status=$state\n" );
|
|
|
|
|
if ( ++$count >= $stateLimit ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-26 19:17:10 +00:00
|
|
|
}
|
2013-07-10 00:15:26 +00:00
|
|
|
}
|
|
|
|
|
} elseif ( $this->hasOption( 'group' ) ) {
|
2015-08-25 08:17:43 +00:00
|
|
|
foreach ( $filteredTypes as $type ) {
|
2013-04-18 18:48:44 +00:00
|
|
|
$queue = $group->get( $type );
|
2013-12-19 19:20:08 +00:00
|
|
|
$delayed = $queue->getDelayedCount();
|
2012-12-14 18:47:06 +00:00
|
|
|
$pending = $queue->getSize();
|
|
|
|
|
$claimed = $queue->getAcquiredCount();
|
2013-03-20 19:40:09 +00:00
|
|
|
$abandoned = $queue->getAbandonedCount();
|
2013-10-10 21:56:11 +00:00
|
|
|
$active = max( 0, $claimed - $abandoned );
|
2014-08-19 21:13:30 +00:00
|
|
|
if ( ( $pending + $claimed + $delayed + $abandoned ) > 0 ) {
|
2013-03-20 19:40:09 +00:00
|
|
|
$this->output(
|
|
|
|
|
"{$type}: $pending queued; " .
|
2013-12-19 19:20:08 +00:00
|
|
|
"$claimed claimed ($active active, $abandoned abandoned); " .
|
|
|
|
|
"$delayed delayed\n"
|
2013-03-20 19:40:09 +00:00
|
|
|
);
|
2012-12-14 18:47:06 +00:00
|
|
|
}
|
2009-08-14 11:15:47 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2012-12-14 18:47:06 +00:00
|
|
|
$count = 0;
|
2015-08-25 08:17:43 +00:00
|
|
|
foreach ( $filteredTypes as $type ) {
|
2012-12-14 18:47:06 +00:00
|
|
|
$count += $group->get( $type )->getSize();
|
|
|
|
|
}
|
|
|
|
|
$this->output( "$count\n" );
|
2009-08-14 11:15:47 +00:00
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-06-29 01:19:14 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = ShowJobs::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|