Add --list parameter to showJobs.php
authorTim Starling <tstarling@wikimedia.org>
Wed, 10 Jul 2013 00:15:26 +0000 (10:15 +1000)
committerTim Starling <tstarling@wikimedia.org>
Wed, 10 Jul 2013 00:16:08 +0000 (10:16 +1000)
For listing all of the jobs in the queue. Post-processing will enable
most sorts of analysis that you would want to do. When we used SQL, this
wasn't reallly necessary, but getting jobs out of Redis is a bit more
tedious.

The format is similar to the log made by runJobs.php.

Change-Id: Idfa3f52ba89638892fc7a64d6566955d66de5958

includes/job/JobQueue.php
maintenance/showJobs.php

index 3295c24..aa47432 100644 (file)
@@ -597,7 +597,7 @@ abstract class JobQueue {
        /**
         * Get an iterator to traverse over all available jobs in this queue.
         * This does not include jobs that are currently acquired or delayed.
-        * This should only be called on a queue that is no longer being popped.
+        * Note: results may be stale if the queue is concurrently modified.
         *
         * @return Iterator
         * @throws MWException
@@ -606,7 +606,7 @@ abstract class JobQueue {
 
        /**
         * Get an iterator to traverse over all delayed jobs in this queue.
-        * This should only be called on a queue that is no longer being popped.
+        * Note: results may be stale if the queue is concurrently modified.
         *
         * @return Iterator
         * @throws MWException
index 322a849..e054a36 100644 (file)
@@ -38,11 +38,22 @@ class ShowJobs extends Maintenance {
                parent::__construct();
                $this->mDescription = "Show number of jobs waiting in master database";
                $this->addOption( 'group', 'Show number of jobs per job type' );
+               $this->addOption( 'list', 'Show a complete list of all jobs in a machine-readable format, instead of statistics' );
        }
 
        public function execute() {
                $group = JobQueueGroup::singleton();
-               if ( $this->hasOption( 'group' ) ) {
+               if ( $this->hasOption( 'list' ) ) {
+                       foreach ( $group->getQueueTypes() as $type ) {
+                               $queue = $group->get( $type );
+                               foreach ( $queue->getAllQueuedJobs() as $job ) {
+                                       $this->output( $job->toString() . " status=unclaimed\n" );
+                               }
+                               foreach ( $queue->getAllDelayedJobs() as $job ) {
+                                       $this->output( $job->toString() . " status=delayed\n" );
+                               }
+                       }
+               } elseif ( $this->hasOption( 'group' ) ) {
                        foreach ( $group->getQueueTypes() as $type ) {
                                $queue = $group->get( $type );
                                $pending = $queue->getSize();