|
@@ -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(),
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
}
|