|
@@ -5,16 +5,31 @@ namespace WorkflowBundle\Services;
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
|
|
|
use PhpAmqpLib\Message\AMQPMessage;
|
|
|
use Symfony\Component\Process\Process;
|
|
|
+use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
|
|
class TaskLoggerService implements ConsumerInterface
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Directorio donde se guardan los script
|
|
|
*/
|
|
|
const TASKLOGGER_PATH = '/tmp/tasklogger';
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var ContainerInterface
|
|
|
+ */
|
|
|
+ protected $serviceContainer;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param ContainerInterface $serviceContainer
|
|
|
+ */
|
|
|
+ public function __construct(ContainerInterface $serviceContainer)
|
|
|
+ {
|
|
|
+ $this->serviceContainer = $serviceContainer;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* $msg will be an instance of `PhpAmqpLib\Message\AMQPMessage`
|
|
|
* with the $msg->body being the data sent over RabbitMQ.
|
|
@@ -27,17 +42,23 @@ class TaskLoggerService implements ConsumerInterface
|
|
|
if (isset($msgBody['id']) && isset($msgBody['content'])) {
|
|
|
$taskloggerId = $msgBody['id'];
|
|
|
$content = $msgBody['content'];
|
|
|
-
|
|
|
+
|
|
|
$filename = $this->createTaskLoggerCmdFile($taskloggerId, $content);
|
|
|
$output = $this->runProcess($filename);
|
|
|
- var_export($output);
|
|
|
+
|
|
|
+ $this->serviceContainer->get('monolog.logger.devicelog')->info($output['output'], [
|
|
|
+ 'deviceType' => $msgBody['entityClass'],
|
|
|
+ 'deviceId' => $msgBody['entityId'],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ var_export($output);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param string $taskloggerId
|
|
|
* @param string $data
|
|
@@ -51,14 +72,14 @@ class TaskLoggerService implements ConsumerInterface
|
|
|
if (!file_exists($tasklogger_dir)) {
|
|
|
mkdir($tasklogger_dir, $mode, true);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$filename = $tasklogger_dir . DIRECTORY_SEPARATOR . 'cmd.sh';
|
|
|
file_put_contents($filename, $data);
|
|
|
chmod($filename, $mode);
|
|
|
-
|
|
|
+
|
|
|
return $filename;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param string $filename
|
|
|
*
|
|
@@ -68,7 +89,7 @@ class TaskLoggerService implements ConsumerInterface
|
|
|
{
|
|
|
$process = new Process($filename);
|
|
|
$process->run();
|
|
|
-
|
|
|
+
|
|
|
return array(
|
|
|
'output' => $process->getOutput(),
|
|
|
'error' => $process->getErrorOutput(),
|