Don't run schedules when a server is suspended or installing; closes #4008
This commit is contained in:
parent
ab37ee8633
commit
b07fdc100c
3 changed files with 46 additions and 1 deletions
|
@ -7,6 +7,7 @@ use Throwable;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Pterodactyl\Models\Schedule;
|
use Pterodactyl\Models\Schedule;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Pterodactyl\Services\Schedules\ProcessScheduleService;
|
use Pterodactyl\Services\Schedules\ProcessScheduleService;
|
||||||
|
|
||||||
class ProcessRunnableCommand extends Command
|
class ProcessRunnableCommand extends Command
|
||||||
|
@ -26,7 +27,9 @@ class ProcessRunnableCommand extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$schedules = Schedule::query()->with('tasks')
|
$schedules = Schedule::query()
|
||||||
|
->with('tasks')
|
||||||
|
->whereRelation('server', fn (Builder $builder) => $builder->whereNull('status'))
|
||||||
->where('is_active', true)
|
->where('is_active', true)
|
||||||
->where('is_processing', false)
|
->where('is_processing', false)
|
||||||
->whereRaw('next_run_at <= NOW()')
|
->whereRaw('next_run_at <= NOW()')
|
||||||
|
|
|
@ -61,6 +61,16 @@ class RunTaskJob extends Job implements ShouldQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
$server = $this->task->server;
|
$server = $this->task->server;
|
||||||
|
// If we made it to this point and the server status is not null it means the
|
||||||
|
// server was likely suspended or marked as reinstalling after the schedule
|
||||||
|
// was queued up. Just end the task right now — this should be a very rare
|
||||||
|
// condition.
|
||||||
|
if (!is_null($server->status)) {
|
||||||
|
$this->failed();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Perform the provided task against the daemon.
|
// Perform the provided task against the daemon.
|
||||||
try {
|
try {
|
||||||
switch ($this->task->action) {
|
switch ($this->task->action) {
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
namespace Pterodactyl\Tests\Integration\Jobs\Schedule;
|
namespace Pterodactyl\Tests\Integration\Jobs\Schedule;
|
||||||
|
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use DateTimeInterface;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use GuzzleHttp\Psr7\Request;
|
use GuzzleHttp\Psr7\Request;
|
||||||
use Pterodactyl\Models\Task;
|
use Pterodactyl\Models\Task;
|
||||||
|
@ -146,6 +148,36 @@ class RunTaskJobTest extends IntegrationTestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that a schedule is not executed if the server is suspended.
|
||||||
|
*
|
||||||
|
* @see https://github.com/pterodactyl/panel/issues/4008
|
||||||
|
*/
|
||||||
|
public function testTaskIsNotRunIfServerIsSuspended()
|
||||||
|
{
|
||||||
|
$server = $this->createServerModel([
|
||||||
|
'status' => Server::STATUS_SUSPENDED,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$schedule = Schedule::factory()->for($server)->create([
|
||||||
|
'last_run_at' => Carbon::now()->subHour(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$task = Task::factory()->for($schedule)->create([
|
||||||
|
'action' => Task::ACTION_POWER,
|
||||||
|
'payload' => 'start',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Bus::dispatchNow(new RunTaskJob($task));
|
||||||
|
|
||||||
|
$task->refresh();
|
||||||
|
$schedule->refresh();
|
||||||
|
|
||||||
|
$this->assertFalse($task->is_queued);
|
||||||
|
$this->assertFalse($schedule->is_processing);
|
||||||
|
$this->assertTrue(Carbon::now()->isSameAs(DateTimeInterface::ATOM, $schedule->last_run_at));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue