Merge pull request #3292 from JulienTant/develop

Make it possible to manually run disable schedule
This commit is contained in:
Dane Everitt 2021-04-25 11:06:18 -07:00 committed by GitHub
commit 4bd1fea52c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 30 deletions

View file

@ -156,10 +156,6 @@ class ScheduleController extends ClientApiController
*/ */
public function execute(TriggerScheduleRequest $request, Server $server, Schedule $schedule) public function execute(TriggerScheduleRequest $request, Server $server, Schedule $schedule)
{ {
if (!$schedule->is_active) {
throw new BadRequestHttpException('Cannot trigger schedule exection for a schedule that is not currently active.');
}
$this->service->handle($schedule, true); $this->service->handle($schedule, true);
return new JsonResponse([], JsonResponse::HTTP_ACCEPTED); return new JsonResponse([], JsonResponse::HTTP_ACCEPTED);

View file

@ -27,13 +27,19 @@ class RunTaskJob extends Job implements ShouldQueue
*/ */
public $task; public $task;
/**
* @var bool
*/
public $manualRun;
/** /**
* RunTaskJob constructor. * RunTaskJob constructor.
*/ */
public function __construct(Task $task) public function __construct(Task $task, $manualRun = false)
{ {
$this->queue = config('pterodactyl.queues.standard'); $this->queue = config('pterodactyl.queues.standard');
$this->task = $task; $this->task = $task;
$this->manualRun = $manualRun;
} }
/** /**
@ -46,8 +52,8 @@ class RunTaskJob extends Job implements ShouldQueue
InitiateBackupService $backupService, InitiateBackupService $backupService,
DaemonPowerRepository $powerRepository DaemonPowerRepository $powerRepository
) { ) {
// Do not process a task that is not set to active. // Do not process a task that is not set to active, unless it's been manually triggered.
if (!$this->task->schedule->is_active) { if (!$this->task->schedule->is_active && !$this->manualRun) {
$this->markTaskNotQueued(); $this->markTaskNotQueued();
$this->markScheduleComplete(); $this->markScheduleComplete();
@ -101,7 +107,7 @@ class RunTaskJob extends Job implements ShouldQueue
$nextTask->update(['is_queued' => true]); $nextTask->update(['is_queued' => true]);
$this->dispatch((new self($nextTask))->delay($nextTask->time_offset)); $this->dispatch((new self($nextTask, $this->manualRun))->delay($nextTask->time_offset));
} }
/** /**

View file

@ -53,7 +53,7 @@ class ProcessScheduleService
$task->update(['is_queued' => true]); $task->update(['is_queued' => true]);
}); });
$job = new RunTaskJob($task); $job = new RunTaskJob($task, $now);
if (!$now) { if (!$now) {
$this->dispatcher->dispatch($job->delay($task->time_offset)); $this->dispatcher->dispatch($job->delay($task->time_offset));

View file

@ -161,7 +161,7 @@ export default () => {
onDeleted={() => history.push(`/server/${id}/schedules`)} onDeleted={() => history.push(`/server/${id}/schedules`)}
/> />
</Can> </Can>
{schedule.isActive && schedule.tasks.length > 0 && {schedule.tasks.length > 0 &&
<Can action={'schedule.update'}> <Can action={'schedule.update'}>
<RunScheduleButton schedule={schedule}/> <RunScheduleButton schedule={schedule}/>
</Can> </Can>

View file

@ -51,26 +51,6 @@ class ExecuteScheduleTest extends ClientApiIntegrationTestCase
}); });
} }
/**
* Test that the schedule is not executed if it is not currently active.
*/
public function testScheduleIsNotExecutedIfNotActive()
{
[$user, $server] = $this->generateTestAccount();
/** @var \Pterodactyl\Models\Schedule $schedule */
$schedule = Schedule::factory()->create([
'server_id' => $server->id,
'is_active' => false,
]);
$response = $this->actingAs($user)->postJson($this->link($schedule, '/execute'));
$response->assertStatus(Response::HTTP_BAD_REQUEST);
$response->assertJsonPath('errors.0.code', 'BadRequestHttpException');
$response->assertJsonPath('errors.0.detail', 'Cannot trigger schedule exection for a schedule that is not currently active.');
}
/** /**
* Test that a user without the schedule update permission cannot execute it. * Test that a user without the schedule update permission cannot execute it.
*/ */