]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/dbqueuemanager.php
Introduced isCurrentProfileInScope() which shall check if current profile is
[quix0rs-gnu-social.git] / lib / dbqueuemanager.php
index c6350fc669227f69403f9b9bb167604a6dbdb4a8..f843d6d9e617286b0b251b55ead91256d3e86fbd 100644 (file)
@@ -44,7 +44,7 @@ class DBQueueManager extends QueueManager
         $qi->created   = common_sql_now();
         $result        = $qi->insert();
 
-        if (!$result) {
+        if ($result === false) {
             common_log_db_error($qi, 'INSERT', __FILE__);
             throw new ServerException('DB error inserting queue item');
         }
@@ -71,36 +71,37 @@ class DBQueueManager extends QueueManager
      */
     public function poll()
     {
-        $this->_log(LOG_DEBUG, 'Checking for notices...');
-        $qi = Queue_item::top($this->getQueues());
+        //$this->_log(LOG_DEBUG, 'Checking for notices...');
+        $qi = Queue_item::top($this->activeQueues());
         if (empty($qi)) {
-            $this->_log(LOG_DEBUG, 'No notices waiting; idling.');
+            //$this->_log(LOG_DEBUG, 'No notices waiting; idling.');
             return false;
         }
 
         $queue = $qi->transport;
-        $item = $this->decode($qi->frame);
+        try {
+            $item = $this->decode($qi->frame);
+        } catch (Exception $e) {
+            $this->_log(LOG_INFO, "[$queue] Discarding: ".$e->getMessage());
+            $this->_done($qi);
+            return true;
+        }
 
-        if ($item) {
-            $rep = $this->logrep($item);
-            $this->_log(LOG_INFO, "Got $rep for transport $queue");
-            
-            $handler = $this->getHandler($queue);
-            if ($handler) {
-                if ($handler->handle($item)) {
-                    $this->_log(LOG_INFO, "[$queue:$rep] Successfully handled item");
-                    $this->_done($qi);
-                } else {
-                    $this->_log(LOG_INFO, "[$queue:$rep] Failed to handle item");
-                    $this->_fail($qi);
-                }
-            } else {
-                $this->_log(LOG_INFO, "[$queue:$rep] No handler for queue $queue; discarding.");
+        $rep = $this->logrep($item);
+        $this->_log(LOG_DEBUG, "Got $rep for transport $queue");
+        
+        $handler = $this->getHandler($queue);
+        if ($handler) {
+            if ($handler->handle($item)) {
+                $this->_log(LOG_INFO, "[$queue:$rep] Successfully handled item");
                 $this->_done($qi);
+            } else {
+                $this->_log(LOG_INFO, "[$queue:$rep] Failed to handle item");
+                $this->_fail($qi);
             }
         } else {
-            $this->_log(LOG_INFO, "[$queue] Got empty/deleted item, discarding");
-            $this->_fail($qi);
+            $this->_log(LOG_INFO, "[$queue:$rep] No handler for queue $queue; discarding.");
+            $this->_done($qi);
         }
         return true;
     }
@@ -135,16 +136,9 @@ class DBQueueManager extends QueueManager
         if (empty($qi->claimed)) {
             $this->_log(LOG_WARNING, "[$queue:item $qi->id] Ignoring failure for unclaimed queue item");
         } else {
-            $orig = clone($qi);
-            $qi->claimed = null;
-            $qi->update($orig);
+            $qi->releaseClaim();
         }
 
         $this->stats('error', $queue);
     }
-
-    protected function _log($level, $msg)
-    {
-        common_log($level, 'DBQueueManager: '.$msg);
-    }
 }