Max execution time margin for OpportunisticQM
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 7 Jan 2016 10:58:09 +0000 (11:58 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 7 Jan 2016 10:58:09 +0000 (11:58 +0100)
I guess it could continue a bit too long in case it got a really long
(failing, timeouting) HTTP request just before max_execution_time hit.

plugins/OpportunisticQM/lib/opportunisticqueuemanager.php

index b2dc61e15fe8bf66ecf1741c00825bf7a50efe25..eeabfa531bbb643d230fe24b090b0e381e3530c3 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