misc_pterodactyl-panel/app/Console/Commands/Schedule/ProcessRunnableCommand.php

63 lines
1.7 KiB
PHP
Raw Normal View History

2017-09-17 04:10:00 +00:00
<?php
namespace Pterodactyl\Console\Commands\Schedule;
use Illuminate\Console\Command;
use Pterodactyl\Models\Schedule;
2017-09-17 04:10:00 +00:00
use Pterodactyl\Services\Schedules\ProcessScheduleService;
class ProcessRunnableCommand extends Command
{
/**
* @var string
*/
protected $signature = 'p:schedule:process';
2017-09-17 04:10:00 +00:00
/**
* @var string
*/
protected $description = 'Process schedules in the database and determine which are ready to run.';
2017-09-17 04:10:00 +00:00
/**
* Handle command execution.
*
* @param \Pterodactyl\Services\Schedules\ProcessScheduleService $service
2017-09-17 04:10:00 +00:00
*
* @throws \Throwable
2017-09-17 04:10:00 +00:00
*/
public function handle(ProcessScheduleService $service)
2018-09-01 03:52:15 +00:00
{
$schedules = Schedule::query()->with('tasks')
->where('is_active', true)
->where('is_processing', false)
->whereRaw('next_run_at <= NOW()')
->get();
2017-09-17 04:10:00 +00:00
if ($schedules->count() < 1) {
$this->line('There are no scheduled tasks for servers that need to be run.');
return;
}
2017-09-17 04:10:00 +00:00
$bar = $this->output->createProgressBar(count($schedules));
foreach ($schedules as $schedule) {
if ($schedule->tasks->isNotEmpty()) {
$service->handle($schedule);
2017-09-17 04:10:00 +00:00
if ($this->input->isInteractive()) {
$bar->clear();
$this->line(trans('command/messages.schedule.output_line', [
'schedule' => $schedule->name,
'hash' => $schedule->hashid,
]));
}
2017-09-17 04:10:00 +00:00
}
$bar->advance();
$bar->display();
}
2017-09-17 04:10:00 +00:00
$this->line('');
}
}