1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2025-02-01 12:31:38 +01:00

Fix an issue when background job (queue:work) not executing

This commit is contained in:
FreeScout 2023-01-18 03:15:17 -08:00
parent 5a1c1bc648
commit 9f0dd50969

View File

@ -31,7 +31,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule) protected function schedule(Schedule $schedule)
{ {
// Keep in mind that this function is also called on clearing cache. // Keep in mind that this function is also called on clearing cache.
// Remove failed jobs // Remove failed jobs
$schedule->command('queue:flush') $schedule->command('queue:flush')
->weekly(); ->weekly();
@ -169,16 +169,21 @@ class Kernel extends ConsoleKernel
shell_exec('kill '.implode(' | kill ', $worker_pids)); shell_exec('kill '.implode(' | kill ', $worker_pids));
} }
} elseif (count($running_commands) == 0) { } elseif (count($running_commands) == 0) {
// Previous queue:work may have been killed or errored and did not remove the mutex. // Make sure 'ps' command actually works.
// So here we are forcefully removing the mutex. $schedule_pids = $this->getRunningQueueProcesses('schedule:run');
$mutex_name = $schedule->command('queue:work', $queue_work_params)
->skip(function () {
return true;
})
->mutexName();
//echo \Cache::get($mutex_name); if (count($schedule_pids)) {
\Cache::forget($mutex_name); // Previous queue:work may have been killed or errored and did not remove the mutex.
// So here we are forcefully removing the mutex.
$mutex_name = $schedule->command('queue:work', $queue_work_params)
->skip(function () {
return true;
})
->mutexName();
if (\Cache::get($mutex_name)) {
\Cache::forget($mutex_name);
}
}
} }
} }
@ -193,12 +198,16 @@ class Kernel extends ConsoleKernel
* *
* @return [type] [description] * @return [type] [description]
*/ */
protected function getRunningQueueProcesses() protected function getRunningQueueProcesses($search = '')
{ {
if (empty($search)) {
$search = \Helper::getWorkerIdentifier();
}
$pids = []; $pids = [];
try { try {
$processes = preg_split("/[\r\n]/", shell_exec("ps aux | grep '".\Helper::getWorkerIdentifier()."'")); $processes = preg_split("/[\r\n]/", shell_exec("ps aux | grep '".$search."'"));
foreach ($processes as $process) { foreach ($processes as $process) {
preg_match("/^[\S]+\s+([\d]+)\s+/", $process, $m); preg_match("/^[\S]+\s+([\d]+)\s+/", $process, $m);
if (!preg_match("/(sh \-c|grep )/", $process) && !empty($m[1])) { if (!preg_match("/(sh \-c|grep )/", $process) && !empty($m[1])) {