From 5c622037a5d7c4267c2091beea1f9eaa0e9e8de3 Mon Sep 17 00:00:00 2001 From: Dmitrii Kustov Date: Sat, 18 May 2024 15:09:48 +0300 Subject: [PATCH] Adjusted conditions for closing the thread --- src/Agent.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Agent.php b/src/Agent.php index e7581d3..f32e3ba 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -215,7 +215,7 @@ private function runTask(array $task): void #Attemp to run $result = $taskInstance->run(); } catch (\Throwable $exception) { - self::log('Failed to run task `'.$task['task'].'`', 'CronTaskFail', true, $exception, ($taskInstance ?? null)); + self::log('Failed to run task `'.$task['task'].'`', 'CronTaskFail', false, $exception, ($taskInstance ?? null)); return; } #Notify of the task finishing @@ -470,15 +470,18 @@ public static function log(string $message, #[ExpectedValues(self::sseStatuses)] echo 'retry: '.((($endStream || $error !== null)) ? 0 : self::$sseRetry)."\n".'id: '.hrtime(true)."\n".(empty($event) ? '' : 'event: '.$event."\n").'data: '.$message."\n\n"; ob_flush(); flush(); - if (($endStream || $error !== null)) { + } + if ($endStream) { + if (self::$CLI === false) { if (!headers_sent()) { header('Connection: close'); } + } + if ($error !== null) { + throw new \RuntimeException($message, previous: $error); + } else { exit; } } - if ($error !== null) { - throw new \RuntimeException($message, previous: $error); - } } }