Explorar o código

FD3-440 se agrega timeout al consumidor, vamos con 10 min.

Maxi Schvindt %!s(int64=7) %!d(string=hai) anos
pai
achega
cd41b09393
Modificáronse 1 ficheiros con 15 adicións e 6 borrados
  1. 15 6
      Services/CommandConsumer.php

+ 15 - 6
Services/CommandConsumer.php

@@ -6,6 +6,7 @@ use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\Process\Process;
+use Symfony\Component\Process\Exception\ProcessFailedException;
 
 class CommandConsumer implements ConsumerInterface
 {
@@ -54,12 +55,20 @@ class CommandConsumer implements ConsumerInterface
             
             $consolePath = $this->serviceContainer->get('kernel')->getRootDir() . '/../bin/console';
             $command = $name . ' ' . implode(' ', $input);
-            $process = new Process("{$consolePath} {$command}");
-            $process->setTimeout(0);
-            $process->run();
-            $content = $process->getOutput();
-            echo $content;
-                        
+            
+            try {
+                $process = new Process("{$consolePath} {$command}");
+                $process->setTimeout(10 * 60);
+                $process->run();
+                
+                $content = $process->getOutput();
+                echo $content;
+            } catch (ProcessFailedException $e) {
+                echo 'KILL COMMAND: ',  $e->getMessage(), "\n";
+            } catch (\Exception $e) {
+                echo 'KILL COMMAND: ',  $e->getMessage(), "\n";
+            }
+            
             return true;
         }