浏览代码

tasklogger service: se quito try catch. se agrego constante. se retorna la salida y el error

Guillermo Espinoza 8 年之前
父节点
当前提交
1cb0cb4c5f
共有 1 个文件被更改,包括 13 次插入11 次删除
  1. 13 11
      Services/TaskLoggerService.php

+ 13 - 11
Services/TaskLoggerService.php

@@ -5,11 +5,16 @@ namespace WorkflowBundle\Services;
 use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
 use Symfony\Component\Process\Process;
-use Symfony\Component\Process\Exception\ProcessFailedException;
 
 class TaskLoggerService implements ConsumerInterface
 {
+    
+    /**
+     * Directorio donde se guardan los script
+     */
+    const TASKLOGGER_DIR = '/tmp/tasklogger';
 
+    
     /**
      * $msg will be an instance of `PhpAmqpLib\Message\AMQPMessage` 
      * with the $msg->body being the data sent over RabbitMQ.
@@ -41,12 +46,12 @@ class TaskLoggerService implements ConsumerInterface
     public function createTaskLoggerCmdFile($taskloggerId, $cmd)
     {
         $mode = 0777;
-        $tasklogger_dir = "/tmp/tasklogger/{$taskloggerId}/";
+        $tasklogger_dir = self::TASKLOGGER_DIR . DIRECTORY_SEPARATOR . $taskloggerId;
         if (!file_exists($tasklogger_dir)) {
             mkdir($tasklogger_dir, $mode, true);
         }
         
-        $file_name = $tasklogger_dir.'cmd.sh';
+        $file_name = $tasklogger_dir . DIRECTORY_SEPARATOR .'cmd.sh';
         file_put_contents($file_name, $cmd);
         chmod($file_name, $mode);
         
@@ -61,15 +66,12 @@ class TaskLoggerService implements ConsumerInterface
     public function runFileProcess($filename)
     {
         $process = new Process($filename);
-        $output = null;
-        try {
-            $process->mustRun();
-            $output = $process->getOutput();
-        } catch (ProcessFailedException $e) {
-            $output = $e->getMessage();
-        }
+        $process->run();
         
-        return $output;
+        return array(
+            'output' => $process->getOutput(),
+            'error' => $process->getErrorOutput(),
+        );
     }
 
 }