DataObjects/core.sql
[Pman.Core] / Notify.php
index 902b7a4..207c6cf 100644 (file)
@@ -158,9 +158,10 @@ class Pman_Core_Notify extends Pman
             
         }
      
-        DB_DataObject::debugLevel(1);
+        //DB_DataObject::debugLevel(1);
         $w = DB_DataObject::factory($this->table);
         
+        
         if (!$showold) {
             
             // standard
@@ -175,7 +176,7 @@ class Pman_Core_Notify extends Pman
     
             $w->orderBy('act_when ASC'); // oldest first.
             
-            echo "QUEUE is {$w->count()}\n";
+            $this->logecho("QUEUE is {$w->count()}");
             
             $w->limit($opts['limit']); // we can run 1000 ...
         } else {
@@ -199,8 +200,8 @@ class Pman_Core_Notify extends Pman
                 $o = $w->object();
                 
                 
-                echo "$w->id : $w->person_id_email email    : ".
-                        $o->toEventString()."    ". $w->status() . "\n";
+                $this->logecho("$w->id : $w->person_id_email email    : ".
+                        $o->toEventString()."    ". $w->status()  );
             }
             exit;
         }
@@ -211,10 +212,10 @@ class Pman_Core_Notify extends Pman
         while (true) {
             
             
-            echo "BATCH SIZE: ".  count($ar) . "\n";
+            $this->logecho("BATCH SIZE: ".  count($ar) );
             
             if (empty($ar)) {
-                echo "COMPLETED MAIN QUEUE - running delated\n";
+                $this->logecho("COMPLETED MAIN QUEUE - running delated");
                 
                 if (empty($pushed)) {
                     break;
@@ -266,8 +267,8 @@ class Pman_Core_Notify extends Pman
         }
         
         
-        
-        die("DONE\n");
+        $this->logecho("DONE");
+        exit;
     }
     
     function run($id, $email, $cmdOpts="")
@@ -309,7 +310,7 @@ class Pman_Core_Notify extends Pman
         
        
         $pipe = array();
-        echo "call proc_open $cmd\n";
+        $this->logecho("call proc_open $cmd");
         
         
         if ($this->max_pool_size === 1) {
@@ -319,7 +320,7 @@ class Pman_Core_Notify extends Pman
         
         
         if (!empty($this->opts['dryrun'])) {
-            echo "DRY RUN\n";
+            $this->logecho("DRY RUN");
             return;
         }
         
@@ -341,7 +342,7 @@ class Pman_Core_Notify extends Pman
             
                 
         );
-        echo "RUN ({$info['pid']}) $cmd  \n";
+        $this->logecho("RUN ({$info['pid']}) $cmd ");
     }
     
     function poolfree()
@@ -358,7 +359,7 @@ class Pman_Core_Notify extends Pman
             
             // update if necessday.
             if ($info['pid'] && $p['pid'] != $info['pid']) {
-                echo "CHANING PID FROM " . $p['pid']  .  "  TO ". $info['pid']. "\n";
+                $this->logecho("CHANING PID FROM " . $p['pid']  .  "  TO ". $info['pid']);
                 $p['pid'] = $info['pid'];
             }
             
@@ -375,7 +376,7 @@ class Pman_Core_Notify extends Pman
                     //fclose($p['pipes'][1]);
                     fclose($p['pipes'][0]);
                     fclose($p['pipes'][2]);
-                    echo "\nTERMINATING: ({$p['pid']}) " . $p['cmd'] . " : " . file_get_contents($p['out']) . "\n";
+                    $this->logecho("TERMINATING: ({$p['pid']}) " . $p['cmd'] . " : " . file_get_contents($p['out']));
                     @unlink($p['out']);
                     
                     continue;
@@ -397,11 +398,11 @@ class Pman_Core_Notify extends Pman
             //    $pool[] = $p;
             //    continue;
             //}
-            echo "\nENDED: ({$p['pid']}) " .  $p['cmd'] . " : " . file_get_contents($p['out']) . "\n";
+            $this->logecho("ENDED: ({$p['pid']}) " .  $p['cmd'] . " : " . file_get_contents($p['out']) );
             @unlink($p['out']);
             //unlink($p['out']);
         }
-        echo "POOL SIZE: ". count($pool) ."\n";
+        $this->logecho("POOL SIZE: ". count($pool) );
         $this->pool = $pool;
         if (count($pool) < $this->max_pool_size) {
             return true;
@@ -430,6 +431,11 @@ class Pman_Core_Notify extends Pman
 
     function output()
     {
-        die("Done\n");
+        $this->logecho("DONE");
+        exit;
+    }
+    function logecho($str)
+    {
+        echo date("Y-m-d H:i:s - ") . $str . "\n";
     }
 }
\ No newline at end of file