Notify.php
[Pman.Core] / Notify.php
index 218cc2b..5a8427e 100644 (file)
@@ -86,7 +86,7 @@ class Pman_Core_Notify extends Pman
         ),
     );
     
-    
+    var $nice_level = false;
     var $max_pool_size = 10;
     
     var $table = 'core_notify';
@@ -248,11 +248,10 @@ class Pman_Core_Notify extends Pman
             $this->poolfree();
              sleep(3);
         }
-        
-        
+         
         foreach($requeue as $p) {
             $pp = clone($p);
-            $p->event_when = strtotime($p->event_when .  ' + 1 MINUTE');
+            $p->act_when = strtotime($p->act_when .  ' + 1 MINUTE');
             $p->update($pp);
             
         }
@@ -264,7 +263,14 @@ class Pman_Core_Notify extends Pman
     
     function run($id, $email, $cmdOpts="")
     {
-       // phpinfo();exit;
+        
+        static $renice = false;
+        if (!$renice) {
+            require_once 'System.php';
+            $renice = System::which('renice');
+        }
+        
+        // phpinfo();exit;
         $tn = tempnam(ini_get('session.save_path'),'stdout') . '.stdout';
         $descriptorspec = array(
             0 => array("pipe", 'r'),  // stdin is a pipe that the child will read from
@@ -289,6 +295,12 @@ class Pman_Core_Notify extends Pman
         echo "call proc_open $cmd\n";
         
         
+        if ($this->max_pool_size === 1) {
+            passthru($cmd);
+            return;
+        }
+        
+        
         if (!empty($this->opts['dryrun'])) {
             echo "DRY RUN\n";
             return;
@@ -296,6 +308,11 @@ class Pman_Core_Notify extends Pman
         
         $p = proc_open($cmd, $descriptorspec, $pipes, $cwd );
         $info =  proc_get_status($p);
+        
+        if ($this->nice_level !== false) { 
+            $rcmd = "$renice {$this->nice_level} {$info['pid']}";
+            `$rcmd`;
+        } 
         $this->pool[] = array(
                 'proc' => $p,
                 'pid' => $info['pid'],
@@ -382,14 +399,15 @@ class Pman_Core_Notify extends Pman
      */
     function poolHasDomain($email)
     {
+        $ret = 0;
         $dom = strtolower(array_pop(explode('@',$email)));
         foreach($this->pool as $p) {
             $mdom = strtolower(array_pop(explode('@',$p['email'])));
             if ($mdom == $dom) {
-                return true;
+                $ret++;
             }
         }
-        return false;
+        return $ret;
         
     }