From 99ef4e68992a286c781af62d47db8cae15577c0b Mon Sep 17 00:00:00 2001 From: FreeScout Date: Mon, 15 Apr 2024 07:17:25 -0700 Subject: [PATCH] Do not run scheduled commands when running \Artisan::call() function - closes #3970 --- app/Console/Kernel.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index e61803ca2..9d943335d 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -32,7 +32,10 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { - // Keep in mind that this function is also called on clearing cache. + // https://github.com/freescout-helpdesk/freescout/issues/3970 + if (!$this->isScheduleRun()) { + return; + } // Remove failed jobs $schedule->command('queue:flush') @@ -108,7 +111,7 @@ protected function schedule(Schedule $schedule) // Kill fetch commands running for too long. // In shedule:run this code is executed every time $schedule->command() in this function is executed. - if ($this->isScheduleRun() && function_exists('shell_exec')) { + if (function_exists('shell_exec')) { $fetch_command_pids = \Helper::getRunningProcesses($fetch_command_identifier); // The name of the command here must be exactly the same as below! @@ -198,7 +201,7 @@ protected function schedule(Schedule $schedule) // and the second 'queue:work' command is launched by cron. When `artisan schedule:run` is executed it sees // that there are two 'queue:work' processes running and kills them. // After one minute 'queue:work' is executed by cron via `artisan schedule:run` and works in the background. - if ($this->isScheduleRun() && function_exists('shell_exec')) { + if (function_exists('shell_exec')) { $running_commands = \Helper::getRunningProcesses(); if (count($running_commands) > 1) { @@ -253,7 +256,7 @@ protected function schedule(Schedule $schedule) */ public function isScheduleRun() { - if (!\Helper::isConsole()) { + if (\Helper::isConsole()) { return true; } else { return !empty($_SERVER['argv']) && in_array('schedule:run', $_SERVER['argv']);