12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace WorkflowBundle\Services;
- use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
- use PhpAmqpLib\Message\AMQPMessage;
- class TaskLoggerService implements ConsumerInterface
- {
- /**
- * $msg will be an instance of `PhpAmqpLib\Message\AMQPMessage`
- * with the $msg->body being the data sent over RabbitMQ.
- *
- * @param AMQPMessage $msg
- */
- public function execute(AMQPMessage $msg)
- {
- $data = unserialize($msg->getBody());
- if (isset($data['id']) && isset($data['cmd'])) {
- $taskloggerId = $data['id'];
- $cmd = $data['cmd'];
- $taskloggerDir = "/tmp/tasklogger/{$taskloggerId}/";
- try {
- if (!file_exists($taskloggerDir)) {
- mkdir($taskloggerDir, 0777, true);
- }
- file_put_contents($taskloggerDir.'cmd.sh', $cmd);
- } catch (\Exception $ex) {
- throw $ex;
- }
- }
-
- return true;
- }
- }
|