]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
OpportunisticQM shouldn't try to handle what it can't find
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 9 Apr 2015 10:15:34 +0000 (12:15 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 9 Apr 2015 10:15:34 +0000 (12:15 +0200)
classes/Queue_item.php
lib/dbqueuemanager.php
plugins/OpportunisticQM/lib/opportunisticqueuemanager.php

index ce7762646d97098a9efe7fd22ccefc02d26c73f4..0d6fd56af278df6adff8654ae4302d4850a94b96 100644 (file)
@@ -82,7 +82,7 @@ class Queue_item extends Managed_DataObject
     /**
      * Release a claimed item.
      */
-    function releaseCLaim()
+    function releaseClaim()
     {
         // DB_DataObject doesn't let us save nulls right now
         $sql = sprintf("UPDATE queue_item SET claimed=NULL WHERE id=%d", $this->id);
index f843d6d9e617286b0b251b55ead91256d3e86fbd..45c4b694d2e4848237bcae4563461fbb79ab55be 100644 (file)
@@ -73,54 +73,57 @@ class DBQueueManager extends QueueManager
     {
         //$this->_log(LOG_DEBUG, 'Checking for notices...');
         $qi = Queue_item::top($this->activeQueues());
-        if (empty($qi)) {
+        if (!$qi instanceof Queue_item) {
             //$this->_log(LOG_DEBUG, 'No notices waiting; idling.');
             return false;
         }
 
-        $queue = $qi->transport;
         try {
             $item = $this->decode($qi->frame);
         } catch (Exception $e) {
-            $this->_log(LOG_INFO, "[$queue] Discarding: ".$e->getMessage());
+            $this->_log(LOG_INFO, "[{$qi->transport}] Discarding: ".$e->getMessage());
             $this->_done($qi);
             return true;
         }
 
         $rep = $this->logrep($item);
-        $this->_log(LOG_DEBUG, "Got $rep for transport $queue");
+        $this->_log(LOG_DEBUG, "Got {$rep} for transport {$qi->transport}");
         
-        $handler = $this->getHandler($queue);
+        $handler = $this->getHandler($qi->transport);
         if ($handler) {
             if ($handler->handle($item)) {
-                $this->_log(LOG_INFO, "[$queue:$rep] Successfully handled item");
+                $this->_log(LOG_INFO, "[{$qi->transport}:$rep] Successfully handled item");
                 $this->_done($qi);
             } else {
-                $this->_log(LOG_INFO, "[$queue:$rep] Failed to handle item");
+                $this->_log(LOG_INFO, "[{$qi->transport}:$rep] Failed to handle item");
                 $this->_fail($qi);
             }
         } else {
-            $this->_log(LOG_INFO, "[$queue:$rep] No handler for queue $queue; discarding.");
-            $this->_done($qi);
+            $this->noHandlerFound($qi, $rep);
         }
         return true;
     }
 
+    // What to do if no handler was found. For example, the OpportunisticQM
+    // should avoid deleting items just because it can't reach XMPP queues etc.
+    protected function noHandlerFound(Queue_item $qi, $rep=null) {
+        $this->_log(LOG_INFO, "[{$qi->transport}:{$rep}] No handler for queue {$qi->transport}; discarding.");
+        $this->_done($qi);
+    }
+
     /**
      * Delete our claimed item from the queue after successful processing.
      *
      * @param QueueItem $qi
      */
-    protected function _done($qi)
+    protected function _done(Queue_item $qi)
     {
-        $queue = $qi->transport;
-
         if (empty($qi->claimed)) {
-            $this->_log(LOG_WARNING, "Reluctantly releasing unclaimed queue item $qi->id from $qi->queue");
+            $this->_log(LOG_WARNING, "Reluctantly releasing unclaimed queue item {$qi->id} from {$qi->transport}");
         }
         $qi->delete();
 
-        $this->stats('handled', $queue);
+        $this->stats('handled', $qi->transport);
     }
 
     /**
@@ -129,16 +132,16 @@ class DBQueueManager extends QueueManager
      *
      * @param QueueItem $qi
      */
-    protected function _fail($qi)
+    protected function _fail(Queue_item $qi, $releaseOnly=false)
     {
-        $queue = $qi->transport;
-
         if (empty($qi->claimed)) {
-            $this->_log(LOG_WARNING, "[$queue:item $qi->id] Ignoring failure for unclaimed queue item");
+            $this->_log(LOG_WARNING, "[{$qi->transport}:item {$qi->id}] Ignoring failure for unclaimed queue item");
         } else {
             $qi->releaseClaim();
         }
 
-        $this->stats('error', $queue);
+        if (!$releaseOnly) {
+            $this->stats('error', $qi->transport);
+        }
     }
 }
index 6356afcd088e781daa7e6e3341a19daf7bbbfebd..4b2b679b580217846dab25d20b03e3b144c5fb08 100644 (file)
@@ -80,6 +80,13 @@ class OpportunisticQueueManager extends DBQueueManager
         return true;
     }
 
+    // OpportunisticQM shouldn't discard items it can't handle, we're
+    // only here to take care of what we _can_ handle!
+    protected function noHandlerFound(Queue_item $qi, $rep=null) {
+        $this->_log(LOG_WARNING, "[{$qi->transport}:item {$qi->id}] Releasing claim for queue item without a handler");
+        $this->_fail($qi, true);    // true here means "releaseOnly", so no error statistics since it's not an _error_
+    }
+
     /**
      * Takes care of running through the queue items, returning when
      * the limits setup in __construct are met.