Skip to content

Commit bffec5b

Browse files
committed
Don't abort the entire schedule running process if one schedule encounters an exception; closes pterodactyl#2609
1 parent 200a78d commit bffec5b

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

app/Console/Commands/Schedule/ProcessRunnableCommand.php

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
namespace Pterodactyl\Console\Commands\Schedule;
44

5+
use Throwable;
6+
use Exception;
57
use Illuminate\Console\Command;
68
use Pterodactyl\Models\Schedule;
9+
use Illuminate\Support\Facades\Log;
710
use Pterodactyl\Services\Schedules\ProcessScheduleService;
811

912
class ProcessRunnableCommand extends Command
@@ -20,12 +23,8 @@ class ProcessRunnableCommand extends Command
2023

2124
/**
2225
* Handle command execution.
23-
*
24-
* @param \Pterodactyl\Services\Schedules\ProcessScheduleService $service
25-
*
26-
* @throws \Throwable
2726
*/
28-
public function handle(ProcessScheduleService $service)
27+
public function handle()
2928
{
3029
$schedules = Schedule::query()->with('tasks')
3130
->where('is_active', true)
@@ -41,22 +40,40 @@ public function handle(ProcessScheduleService $service)
4140

4241
$bar = $this->output->createProgressBar(count($schedules));
4342
foreach ($schedules as $schedule) {
44-
if ($schedule->tasks->isNotEmpty()) {
45-
$service->handle($schedule);
46-
47-
if ($this->input->isInteractive()) {
48-
$bar->clear();
49-
$this->line(trans('command/messages.schedule.output_line', [
50-
'schedule' => $schedule->name,
51-
'hash' => $schedule->hashid,
52-
]));
53-
}
54-
}
55-
43+
$bar->clear();
44+
$this->processSchedule($schedule);
5645
$bar->advance();
5746
$bar->display();
5847
}
5948

6049
$this->line('');
6150
}
51+
52+
/**
53+
* Processes a given schedule and logs and errors encountered the console output. This should
54+
* never throw an exception out, otherwise you'll end up killing the entire run group causing
55+
* any other schedules to not process correctly.
56+
*
57+
* @param \Pterodactyl\Models\Schedule $schedule
58+
* @see https://github.com/pterodactyl/panel/issues/2609
59+
*/
60+
protected function processSchedule(Schedule $schedule)
61+
{
62+
if ($schedule->tasks->isEmpty()) {
63+
return;
64+
}
65+
66+
try {
67+
$this->getLaravel()->make(ProcessScheduleService::class)->handle($schedule);
68+
69+
$this->line(trans('command/messages.schedule.output_line', [
70+
'schedule' => $schedule->name,
71+
'hash' => $schedule->hashid,
72+
]));
73+
} catch (Throwable | Exception $exception) {
74+
Log::error($exception, ['schedule_id' => $schedule->id]);
75+
76+
$this->error("An error was encountered while processing Schedule #{$schedule->id}: " . $exception->getMessage());
77+
}
78+
}
6279
}

0 commit comments

Comments
 (0)