Forráskód Böngészése

Se actualizo rabbitMQ producer y consumer. Fix twig exception

Guillermo Espinoza 7 éve
szülő
commit
a65822e82b

+ 9 - 11
Event/EventSubscriber.php

@@ -107,30 +107,28 @@ class EventSubscriber implements EventSubscriberInterface
         return $actions;
     }
 
-    public function completeAction($action, $params) {
-        
+    public function completeAction($action, $params)
+    {
+
         $logger = $this->container->get('logger');
 
         $object = $params['entity'];
         $this->producerService->publishMessage($action, $object);
 
-        
         $template = $action->getTemplate();
-        $twig = new \Twig_Environment(new \Twig_Loader_String());
-        $rendered = $twig->render($template, $params);
+        $twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
+        $tpl = $twig->createTemplate($template);
+        $rendered = $tpl->render($params);
 
         $class = get_class($object);
-        
+
         $logger->info("ACTION (action_id_{$action->getId()}) {$action->getName()} | Task: '{$rendered}' => {$class}_id_{$object->getId()}");
-        
+
         // $string = file_get_contents("/var/flowdat/ftth/out.log");
-            
         // $string .= "### Action id :".$action->getId().PHP_EOL;
         // $string .= "----------------------".PHP_EOL.$template.PHP_EOL;
         // $string .= "----------------------".PHP_EOL.$rendered.PHP_EOL.PHP_EOL;
-        
         // file_put_contents("/var/flowdat/ftth/out.log", $string);
-
     }
-    
+
 }

+ 1 - 0
Resources/config/rabbit_mq/services.yml

@@ -5,6 +5,7 @@ parameters:
 services:
     flowdat_tasklogger_service:
         class: '%tasklogger_service.class%'
+        arguments: ['@service_container']
     workflow.producer_service:
         class: '%workflow.producer_service.class%'
         arguments: ['@service_container']

+ 6 - 5
Services/ProducerService.php

@@ -84,16 +84,17 @@ class ProducerService
      */
     public function publishMessage(Action $action, $entity)
     {
+        $entityClass = get_class($entity);
+        $actionName = $action->getName();
+        $entityId = $entity->getId();
         $msg = array(
             'id' => uniqid(),
             'content' => $action->render($entity),
+            'entityClass' => $entityClass,
+            'entityId' => $entityId,
         );
         $this->producer->publish(serialize($msg));
-        
-        $entityClass = get_class($entity);
-        $actionName = $action->getName();
-        $entityId = $entity->getId();
-        
+                
         $msg = serialize($msg);
 
         $logger = $this->serviceContainer->get('logger');

+ 31 - 10
Services/TaskLoggerService.php

@@ -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(),