jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/368116 )
Change subject: Create new wmfManageJobs.php for deleting queues from deleted
wikis
..
Create new wmfManageJobs.php for deleting queues from deleted wikis
Tested on the Beta Cluster:
$ mwscript eval.php --wiki aawiki
> $i = 1000; while ( $i-- ) { JobQueueGroup::singleton()->push( new NullJob(
> Title::newMainPage(), [ 'usleep' => 100, 'lives' => 5 ] ) ); }
$ mwscript ~/wmfManageJobs.php --wiki=aawiki --target=aawiki
> null: 515 queued; 5 claimed (5 active, 0 abandoned); 0 delayed
> refreshLinksPrioritized: 0 queued; (empty or doesn't exist)
>
> Run the script again with --delete to delete these queues.
$ mwscript ~/wmfManageJobs.php --wiki=aawiki --target=aawiki --delete
> null: 241 queued; 4 claimed (4 active, 0 abandoned); 0 delayed
> refreshLinksPrioritized: 0 queued; (empty or doesn't exist)
>
> The script will now delete 241 job(s), from 2 different queue(s), for this
> wiki: aawiki
> Abort with control-C in the next five seconds...0
> null: deleting...
> refreshLinksPrioritized: deleting...
> Done!
Bug: T171371
Change-Id: I29895db8c719abdd56ec773a79ef4287af2ac68b
---
A wmfManageJobs.php
1 file changed, 128 insertions(+), 0 deletions(-)
Approvals:
BryanDavis: Looks good to me, approved
jenkins-bot: Verified
diff --git a/wmfManageJobs.php b/wmfManageJobs.php
new file mode 100644
index 000..88284b8
--- /dev/null
+++ b/wmfManageJobs.php
@@ -0,0 +1,128 @@
+http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Maintenance
+ */
+
+require_once __DIR__ . '/WikimediaMaintenance.php';
+
+/**
+ * WMF-specific version of mediawiki/maintenance/manageJobs.php.
+ *
+ * Main use case is to be able to perform actions on the job queue even for
+ * Wiki IDs that are no longer recognised by MediaWiki.
+ * It communicates directly with the job queue using the Job Config of
+ * the wiki the script was run from, under the assumption that all wikis
+ * share the same job queue configuration. (Or at least the target wiki,
+ * and the used wiki).
+ *
+ * For regular wikis that still exist and operate normally, prefer
+ * using MediaWiki core's manageJobs.php instead.
+ *
+ * Show current queues (like showJobs.php):
+ *
+ * $ mwscript extensions/WikimediaMaintenance/wmfManageJobs.php --wiki=aawiki
--target=testwiki
+ *
+ * Delete current queues (like manageJobs.php --delete):
+ *
+ * $ mwscript extensions/WikimediaMaintenance/wmfManageJobs.php --wiki=aawiki
--target=testwiki --delete
+ */
+class WmfManageJobs extends Maintenance {
+ public function __construct() {
+ parent::__construct();
+ $this->addDescription( 'Manage job queue for a particular
wiki-id' );
+ $this->addOption( 'target', 'Which Wiki-ID to operate on',
true, true );
+ $this->addOption( 'delete', 'Delete all queues for this wiki
ID', false, false );
+ }
+
+ public function execute() {
+ $target = $this->getOption( 'target' );
+ $delete = $this->hasOption( 'delete' );
+
+ $group = JobQueueGroup::singleton( $target );
+
+ /**
+* Get a list of job types for this wiki
+* - Can't use $group->getQueueTypes() because that it uses
SiteConfig
+* to read 'wgJobClasses' from the target wiki, which may not
exist
+* - Can't use `$this->getConfig()->get( 'JobClasses' )`
because which
+* jobs are recognised varies from one wiki to another (which
extensions
+* are installed etc, there is no "catch-all" registry)
+* - Workaround it by levering JobQueueAggregator, which tracks
jobs
+* in a structured globally keyed by job type first.
+*/
+ $aggregator = JobQueueAggregator::singleton();
+ $types = array_keys( $aggregator->getAllReadyWikiQueues() );
+
+ $deleteTypes = [];
+ $total = 0;
+
+ // Show current job queue status
+ // (Based on mediawiki/maintenance/showJobs.php)
+ foreach ( $types as $type ) {
+ $queue = $group->get( $type );
+ $pending = $queue->getSize();
+ $delayed = $queue->getDelayedCount();
+ $claimed = $queue->getAcquiredCount();
+ $abandoned = $queue->getAbandonedCount();
+ $subtotal = $pending + $delayed + $claimed + $abandoned;
+ if ( $subtotal ) {
+ $total += $subtotal;
+ $active = max( 0, $claimed - $abandoned );
+ $this->output(
+ "{$type}: $pending queued; " .
+