Pārlūkot izejas kodu

Capture timeout and other error, this try and catch permit remove message from amqp.

Gabriel Gosparo 6 gadi atpakaļ
vecāks
revīzija
9444168da0
1 mainītis faili ar 17 papildinājumiem un 7 dzēšanām
  1. 17 7
      Services/TaskLoggerService.php

+ 17 - 7
Services/TaskLoggerService.php

@@ -97,14 +97,24 @@ class TaskLoggerService implements ConsumerInterface
     	$predir = getcwd();
     	chdir(dirname($filename));
         $process = new Process($filename);
-        $process->run();
-    	chdir($predir);
-	
-
+        try {
+            $process->run();
+    	    chdir($predir);
+    	    $output = $process->getOutput();
+            $error = $process->getErrorOutput();
+            $exit_code = $process->getExitCode();
+	    } catch (\Throwable $t) {
+	        $output = $filename . 
+	            "\n==================================ERROR==================================\n";
+            $error = "\n==================================ERROR==================================\n" .
+                $t->getMessage() . "\n" . $t->getTraceAsString() . 
+                "\n==================================ERROR==================================\n";
+            $exit_code = $t->getCode();
+        }
         return array(
-            'output' => $process->getOutput(),
-            'error' => $process->getErrorOutput(),
-            'exit_code' => $process->getExitCode(),
+            'output' => $output,
+            'error' => $error,
+            'exit_code' => $exit_code,
         );
     }