TaskLoggerService.php 1010 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace WorkflowBundle\Services;
  3. use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
  4. use PhpAmqpLib\Message\AMQPMessage;
  5. class TaskLoggerService implements ConsumerInterface
  6. {
  7. /**
  8. * $msg will be an instance of `PhpAmqpLib\Message\AMQPMessage`
  9. * with the $msg->body being the data sent over RabbitMQ.
  10. *
  11. * @param AMQPMessage $msg
  12. */
  13. public function execute(AMQPMessage $msg)
  14. {
  15. $data = unserialize($msg->getBody());
  16. if (isset($data['id']) && isset($data['cmd'])) {
  17. $taskloggerId = $data['id'];
  18. $cmd = $data['cmd'];
  19. $taskloggerDir = "/tmp/tasklogger/{$taskloggerId}/";
  20. try {
  21. if (!file_exists($taskloggerDir)) {
  22. mkdir($taskloggerDir, 0777, true);
  23. }
  24. file_put_contents($taskloggerDir.'cmd.sh', $cmd);
  25. } catch (\Exception $ex) {
  26. throw $ex;
  27. }
  28. }
  29. return true;
  30. }
  31. }