Guillermo Espinoza пре 8 година
родитељ
комит
79de983588
3 измењених фајлова са 29 додато и 6 уклоњено
  1. 10 0
      Entity/Action.php
  2. 2 3
      EventListener/DoctrineEventSubscriber.php
  3. 17 3
      Services/TaskLoggerService.php

+ 10 - 0
Entity/Action.php

@@ -311,5 +311,15 @@ class Action
     {
         return $this->tenancyId;
     }
+    
+    /**
+     * @param Entity $entity
+     * 
+     * @return string
+     */
+    public function getCmd($entity)
+    {
+        return '';
+    }
 
 }

+ 2 - 3
EventListener/DoctrineEventSubscriber.php

@@ -99,9 +99,8 @@ class DoctrineEventSubscriber implements EventSubscriber
                 $actions = $doctrine2WorkFlowAction->getActions();
                 foreach ($actions as $action) {
                     $msg = array(
-                        'msg' => 'bash script',
-                        'action' => $action,
-                        'entity' => $entity,
+                        'id' => uniqid(),
+                        'cmd' => $action->getCmd($entity),
                     );
                     $this->producer->publish(serialize($msg));
                 }

+ 17 - 3
Services/TaskLoggerService.php

@@ -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;
     }