Krinkle has uploaded a new change for review. ( 
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

Bug: T171371
Change-Id: I29895db8c719abdd56ec773a79ef4287af2ac68b
---
A wmfManageJobs.php
1 file changed, 119 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaMaintenance 
refs/changes/16/368116/1

diff --git a/wmfManageJobs.php b/wmfManageJobs.php
new file mode 100644
index 0000000..8f92de0
--- /dev/null
+++ b/wmfManageJobs.php
@@ -0,0 +1,119 @@
+<?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
+ * @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.
+ *
+ * Usage:
+ *
+ *  $ mwscript extensions/WikimediaMaintenance/wmfManageJobs.php --wiki=aawiki 
--target=example
+ */
+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 );
+                       if ( !$queue ) {
+                               $this->output( "{$type}: (does not exist for 
this wiki)" );
+                               continue;
+                       }
+                       $pending = $queue->getSize();
+                       $delayed = $queue->getDelayedCount();
+                       $claimed = $queue->getAcquiredCount();
+                       $abandoned = $queue->getAbandonedCount();
+                       $subtotal = $pending + $delayed + $claimed + $abandoned;
+                       if ( $subtotal ) {
+                               $active = max( 0, $claimed - $abandoned );
+                               $this->output(
+                                       "{$type}: $pending queued; " .
+                                       "$claimed claimed ($active active, 
$abandoned abandoned); " .
+                                       "$delayed delayed\n"
+                               );
+                               $deleteTypes[$type] = $queue;
+                               $total += $subtotal;
+                       }
+               }
+
+               if ( !$deleteTypes ) {
+                       $this->output( "\nNo queues found for $target.\n" );
+                       return;
+               }
+
+               if ( !$delete ) {
+                       $this->output( "\nRun the script again with --delete to 
delete these queues.\n" );
+                       return;
+               }
+
+               $count = count( $deleteTypes );
+               $this->output( "\n\nThe script will now delete $total job(s), " 
.
+                       "from $count different type(s), for this wiki: 
$target\n" );
+               $this->output( 'Abort with control-C in the next five 
seconds...' );
+               wfCountDown( 5 );
+
+               foreach ( $deleteTypes as $type => $queue ) {
+                       $this->output( "$type: deleting...\n" );
+                       $queue->delete();
+                       $this->output( "$type: done (current size: 
{$queue->getSize()}).\n" );
+               }
+       }
+}
+
+$maintClass = WmfManageJobs::class;
+require_once RUN_MAINTENANCE_IF_MAIN;

-- 
To view, visit https://gerrit.wikimedia.org/r/368116
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I29895db8c719abdd56ec773a79ef4287af2ac68b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikimediaMaintenance
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to