Made showJobs.php include abandoned jobs in --list
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 26 Mar 2015 19:17:10 +0000 (12:17 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 26 Mar 2015 19:17:10 +0000 (12:17 -0700)
Change-Id: I7ae8dd2470d5e15fd66c6c06f3feb6d70527daa3

includes/jobqueue/JobQueue.php
includes/jobqueue/JobQueueFederated.php
includes/jobqueue/JobQueueRedis.php
maintenance/showJobs.php

index f4fe913..91fe86c 100644 (file)
@@ -615,6 +615,17 @@ abstract class JobQueue {
                return new ArrayIterator( array() ); // not implemented
        }
 
+       /**
+        * Get an iterator to traverse over all abandoned jobs in this queue
+        *
+        * @return Iterator
+        * @throws JobQueueError
+        * @since 1.25
+        */
+       public function getAllAbandonedJobs() {
+               return new ArrayIterator( array() ); // not implemented
+       }
+
        /**
         * Do not use this function outside of JobQueue/JobQueueGroup
         *
index 1d84dc4..d985d44 100644 (file)
@@ -422,6 +422,17 @@ class JobQueueFederated extends JobQueue {
                return $iterator;
        }
 
+       public function getAllAbandonedJobs() {
+               $iterator = new AppendIterator();
+
+               /** @var JobQueue $queue */
+               foreach ( $this->partitionQueues as $queue ) {
+                       $iterator->append( $queue->getAllAbandonedJobs() );
+               }
+
+               return $iterator;
+       }
+
        public function getCoalesceLocationInternal() {
                return "JobQueueFederated:wiki:{$this->wiki}" .
                        sha1( serialize( array_keys( $this->partitionQueues ) ) );
index d9fe30b..6c823fb 100644 (file)
@@ -516,6 +516,29 @@ LUA;
                }
        }
 
+       /**
+        * @see JobQueue::getAllAbandonedJobs()
+        * @return Iterator
+        */
+       public function getAllAbandonedJobs() {
+               $conn = $this->getConnection();
+               try {
+                       $that = $this;
+
+                       return new MappedIterator( // delayed jobs
+                               $conn->zRange( $this->getQueueKey( 'z-abandoned' ), 0, -1 ),
+                               function ( $uid ) use ( $that, $conn ) {
+                                       return $that->getJobFromUidInternal( $uid, $conn );
+                               },
+                               array( 'accept' => function ( $job ) {
+                                       return is_object( $job );
+                               } )
+                       );
+               } catch ( RedisException $e ) {
+                       $this->throwRedisException( $conn, $e );
+               }
+       }
+
        public function getCoalesceLocationInternal() {
                return "RedisServer:" . $this->server;
        }
index a9f7d8b..9e9ad32 100644 (file)
@@ -58,6 +58,9 @@ class ShowJobs extends Maintenance {
                                foreach ( $queue->getAllDelayedJobs() as $job ) {
                                        $this->output( $job->toString() . " status=delayed\n" );
                                }
+                               foreach ( $queue->getAllAbandonedJobs() as $job ) {
+                                       $this->output( $job->toString() . " status=abandoned\n" );
+                               }
                        }
                } elseif ( $this->hasOption( 'group' ) ) {
                        foreach ( $group->getQueueTypes() as $type ) {