1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-25 20:02:30 +01:00
freescout/app/Console/Kernel.php

95 lines
2.8 KiB
PHP
Raw Normal View History

2018-06-22 19:44:21 +02:00
<?php
namespace App\Console;
2018-08-15 08:10:05 +02:00
use Carbon\Carbon;
2018-06-22 19:44:21 +02:00
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
2018-09-24 15:07:07 +02:00
// It is not clear what for this array
//\App\Console\Commands\CreateUser::class,
2018-06-22 19:44:21 +02:00
];
/**
* Define the application's command schedule.
*
2018-07-24 08:34:28 +02:00
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
2018-06-22 19:44:21 +02:00
* @return void
*/
protected function schedule(Schedule $schedule)
{
2018-08-02 18:17:13 +02:00
// Remove failed jobs
$schedule->command('queue:flush')
->daily();
// Restart processing queued jobs (just in case)
$schedule->command('queue:restart')
->hourly();
2018-09-24 15:07:07 +02:00
$schedule->command('freescout:fetch-monitor')
->everyMinute()
->withoutOverlapping();
2018-11-12 13:40:23 +01:00
$schedule->command('freescout:module-check-licenses')
->daily();
2018-08-03 20:56:06 +02:00
// Fetch emails from mailboxes
2018-08-08 09:52:53 +02:00
$schedule->command('freescout:fetch-emails')
->everyMinute()
->withoutOverlapping()
->sendOutputTo(storage_path().'/logs/fetch-emails.log');
2018-08-03 20:56:06 +02:00
2018-08-02 18:17:13 +02:00
// Command runs as subprocess and sets cache mutex. If schedule:run command is killed
2018-08-02 18:18:32 +02:00
// subprocess does not clear the mutex and it stays in the cache until cache:clear is executed.
2018-08-02 18:17:13 +02:00
// By default, the lock will expire after 24 hours.
2018-11-12 10:12:57 +01:00
//
2018-08-15 08:10:05 +02:00
// cache:clear clears the mutex, but sometimes process continues running, so we need to kill it.
2018-11-12 10:12:57 +01:00
2018-08-15 08:10:05 +02:00
if (function_exists('shell_exec')) {
$running_commands = 0;
2018-11-12 10:12:57 +01:00
2018-08-15 08:10:05 +02:00
try {
$processes = preg_split("/[\r\n]/", shell_exec("ps aux | grep 'queue:work'"));
foreach ($processes as $process) {
preg_match("/^[\S]+\s+([\d]+)\s+/", $process, $m);
if (!preg_match("/(sh \-c|grep )/", $process) && !empty($m[1])) {
$running_commands++;
}
}
} catch (\Exception $e) {
// Do nothing
}
if ($running_commands > 1) {
// queue:work command is stopped by settings a cache key
\Cache::forever('illuminate:queue:restart', Carbon::now()->getTimestamp());
}
}
2018-08-02 18:17:13 +02:00
$schedule->command('queue:work', Config('app.queue_work_params'))
2018-08-03 20:56:06 +02:00
->everyMinute()
2018-08-02 18:17:13 +02:00
->withoutOverlapping()
2018-08-02 18:18:32 +02:00
->sendOutputTo(storage_path().'/logs/queue-jobs.log');
2018-06-22 19:44:21 +02:00
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}