]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OpportunisticQM/lib/opportunisticqueuemanager.php
Merge remote-tracking branch 'upstream/master'
[quix0rs-gnu-social.git] / plugins / OpportunisticQM / lib / opportunisticqueuemanager.php
index 86a77150dec12567f5b729dc32d0209e28ae2eaa..c0339f958b5e4a2bdcf7b751ecd53f66612c2b62 100644 (file)
@@ -18,12 +18,13 @@ class OpportunisticQueueManager extends DBQueueManager
 {
     protected $qmkey = false;
     protected $max_execution_time = null;
+    protected $max_execution_margin = null; // margin to execution time, including timeouts etc.
     protected $max_queue_items = null;
 
     protected $started_at = null;
     protected $handled_items = 0;
 
-    const MAXEXECTIME = 30; // typically just used for the /main/cron action
+    const MAXEXECTIME = 10; // typically just used for the /main/cron action, only used if php.ini max_execution_time is 0
 
     public function __construct(array $args=array()) {
         foreach (get_class_vars(get_class($this)) as $key=>$val) {
@@ -41,6 +42,10 @@ class OpportunisticQueueManager extends DBQueueManager
             $this->max_execution_time = ini_get('max_execution_time') ?: self::MAXEXECTIME;
         }
 
+        if ($this->max_execution_margin === null) {
+            $this->max_execution_margin = 10;    // should be calculated from our default timeouts for http requests etc.
+        }
+
         return parent::__construct();
     }
 
@@ -60,7 +65,7 @@ class OpportunisticQueueManager extends DBQueueManager
             return false;
         }
         // If too much time has passed, stop
-        if ($time_passed >= $this->max_execution_time) {
+        if ($time_passed >= $this->max_execution_time - $this->max_execution_margin) {
             return false;
         }
         // If we have a max-item-limit, check if it has been passed
@@ -83,10 +88,17 @@ class OpportunisticQueueManager extends DBQueueManager
     // 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->_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_
     }
 
+    protected function _fail(Queue_item $qi, $releaseOnly=false)
+    {
+        parent::_fail($qi, $releaseOnly);
+        $this->_log(LOG_DEBUG, "[{$qi->transport}:item {$qi->id}] Ignoring this transport for the rest of this execution");
+        $this->ignoreTransport($qi->transport);
+    }
+
     /**
      * Takes care of running through the queue items, returning when
      * the limits setup in __construct are met.