GCTC-NTGC /
TalentCloud
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Console; |
||
| 4 | |||
| 5 | use App\Jobs\ProcessJobStatusTransitions; |
||
| 6 | use Illuminate\Console\Scheduling\Schedule; |
||
| 7 | use Illuminate\Foundation\Console\Kernel as ConsoleKernel; |
||
| 8 | use Illuminate\Support\Facades\Log; |
||
| 9 | |||
| 10 | class Kernel extends ConsoleKernel |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * The Artisan commands provided by your application. |
||
| 14 | * |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | protected $commands = [ |
||
| 18 | ]; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Define the application's command schedule. |
||
| 22 | * |
||
| 23 | * @param \Illuminate\Console\Scheduling\Schedule $schedule |
||
| 24 | * @return void |
||
| 25 | 102 | */ |
|
| 26 | protected function schedule(Schedule $schedule): void |
||
| 27 | { |
||
| 28 | // Open and Close datetimes are likely to be on the hour, |
||
| 29 | // so checking them one minute after the hour should always catch the transitions. |
||
| 30 | $schedule->job(new ProcessJobStatusTransitions())->hourlyAt(1); |
||
| 31 | 102 | ||
| 32 | 102 | // start the queue daemon, if its not running |
|
| 33 | if (!$this->osProcessIsRunning('queue:work')) { |
||
| 34 | 102 | $schedule->command('queue:work')->everyMinute(); |
|
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Register the commands for the application. |
||
| 40 | * |
||
| 41 | 102 | * @return void |
|
| 42 | */ |
||
| 43 | 102 | protected function commands(): void |
|
| 44 | { |
||
| 45 | 102 | $this->load(__DIR__ . '/Commands'); |
|
| 46 | 102 | ||
| 47 | require base_path('routes/console.php'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * checks, if a process with $needle in the name is running |
||
| 52 | * |
||
| 53 | * @param string $needle |
||
| 54 | 102 | * @return boolean |
|
| 55 | */ |
||
| 56 | protected function osProcessIsRunning(string $needle): bool |
||
| 57 | 102 | { |
|
| 58 | // get process status. the "-ww"-option is important to get the full output! |
||
| 59 | exec('ps aux -ww', $process_status); |
||
| 60 | |||
| 61 | 102 | ||
| 62 | 102 | // search $needle in process status |
|
| 63 | $result = array_filter( |
||
| 64 | $process_status, |
||
| 65 | 102 | function ($var) use ($needle) { |
|
| 66 | return strpos($var, $needle); |
||
| 67 | } |
||
| 68 | ); |
||
| 69 | 102 | ||
| 70 | // if the result is not empty, the needle exists in running processes |
||
| 71 | if (!empty($result)) { |
||
| 72 | return true; |
||
| 73 | 102 | } |
|
| 74 | |||
| 75 | return false; |
||
| 76 | } |
||
| 77 | } |
||
| 78 |