Changed Notify.php
authorAlan Knowles <alan@roojs.com>
Fri, 6 Aug 2021 05:25:52 +0000 (13:25 +0800)
committerAlan Knowles <alan@roojs.com>
Fri, 6 Aug 2021 05:25:52 +0000 (13:25 +0800)
Notify.php

index 98ce558..45607c0 100644 (file)
@@ -97,10 +97,19 @@ class Pman_Core_Notify extends Pman
     var $max_to_domain = 10;
     
     /**
-     * @var $maxruntime - maximum time a child is allowed to run - defaut 2 minutes
+     * @var $maxruntime - maximum seconds a child is allowed to run - defaut 2 minutes
      */
     var $maxruntime = 120;
     
+    /**
+    * @var {Boolean} log_events - default true if events should be logged.
+    */
+    var $log_events = true;
+    /**
+    * @var {Number} try_again_minutes how long after failing to try again default = 30 if max runtime fails
+    */
+    var $try_again_minutes = 30;
+    
     var $table = 'core_notify';
     var $target = 'Core/NotifySend';
     var $evtype = ''; // any notification...
@@ -311,7 +320,7 @@ class Pman_Core_Notify extends Pman
     
     
     
-    function run($id, $email, $cmdOpts="")
+    function run($id, $email='', $cmdOpts="")
     {
         
         static $renice = false;
@@ -321,9 +330,9 @@ class Pman_Core_Notify extends Pman
         }
         
         // phpinfo();exit;
-        $tnx = tempnam(ini_get('session.save_path'),'stdout');
-        unlink($tnx);
-        $tn =  $tnx . '.stdout';
+        
+        
+        $tn =  $this->tempName('stdout', true);
         $descriptorspec = array(
             0 => array("pipe", 'r'),  // stdin is a pipe that the child will read from
             1 => array("file", $tn, 'w'),  // stdout is a pipe that the child will write to
@@ -419,14 +428,16 @@ class Pman_Core_Notify extends Pman
                     $this->logecho("TERMINATING: ({$p['pid']}) " . $p['cmd'] . " : " . file_get_contents($p['out']));
                     @unlink($p['out']);
                     
+                    // schedule again
                     $w = DB_DataObject::factory($this->table);
                     $w->get($p['notify_id']);
                     $ww = clone($w);
-                    $this->addEvent('NOTIFY', $w, 'TERMINATED - TIMEOUT');
-                    $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + 30  MINUTES'));
+                    if ($this->log_events) {
+                        $this->addEvent('NOTIFY', $w, 'TERMINATED - TIMEOUT');
+                    }
+                    $w->act_when = date('Y-m-d H:i:s', strtotime("NOW + {$this->try_again_minutes} MINUTES"));
                     $w->update($ww);
                     
-                    
                     continue;
                 }