|
@@ -9,13 +9,27 @@ 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)
|
|
|
{
|
|
|
- //$msg will be an instance of `PhpAmqpLib\Message\AMQPMessage` with the $msg->body being the data sent over RabbitMQ.
|
|
|
-
|
|
|
- $data = $msg->body;
|
|
|
+ $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;
|
|
|
}
|