Skip to content

Commit 4bd1fea

Browse files
authored
Merge pull request pterodactyl#3292 from JulienTant/develop
Make it possible to manually run disable schedule
2 parents d0c7e2c + b10f618 commit 4bd1fea

File tree

5 files changed

+12
-30
lines changed

5 files changed

+12
-30
lines changed

app/Http/Controllers/Api/Client/Servers/ScheduleController.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ public function update(UpdateScheduleRequest $request, Server $server, Schedule
156156
*/
157157
public function execute(TriggerScheduleRequest $request, Server $server, Schedule $schedule)
158158
{
159-
if (!$schedule->is_active) {
160-
throw new BadRequestHttpException('Cannot trigger schedule exection for a schedule that is not currently active.');
161-
}
162-
163159
$this->service->handle($schedule, true);
164160

165161
return new JsonResponse([], JsonResponse::HTTP_ACCEPTED);

app/Jobs/Schedule/RunTaskJob.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ class RunTaskJob extends Job implements ShouldQueue
2727
*/
2828
public $task;
2929

30+
/**
31+
* @var bool
32+
*/
33+
public $manualRun;
34+
3035
/**
3136
* RunTaskJob constructor.
3237
*/
33-
public function __construct(Task $task)
38+
public function __construct(Task $task, $manualRun = false)
3439
{
3540
$this->queue = config('pterodactyl.queues.standard');
3641
$this->task = $task;
42+
$this->manualRun = $manualRun;
3743
}
3844

3945
/**
@@ -46,8 +52,8 @@ public function handle(
4652
InitiateBackupService $backupService,
4753
DaemonPowerRepository $powerRepository
4854
) {
49-
// Do not process a task that is not set to active.
50-
if (!$this->task->schedule->is_active) {
55+
// Do not process a task that is not set to active, unless it's been manually triggered.
56+
if (!$this->task->schedule->is_active && !$this->manualRun) {
5157
$this->markTaskNotQueued();
5258
$this->markScheduleComplete();
5359

@@ -101,7 +107,7 @@ private function queueNextTask()
101107

102108
$nextTask->update(['is_queued' => true]);
103109

104-
$this->dispatch((new self($nextTask))->delay($nextTask->time_offset));
110+
$this->dispatch((new self($nextTask, $this->manualRun))->delay($nextTask->time_offset));
105111
}
106112

107113
/**

app/Services/Schedules/ProcessScheduleService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function handle(Schedule $schedule, bool $now = false)
5353
$task->update(['is_queued' => true]);
5454
});
5555

56-
$job = new RunTaskJob($task);
56+
$job = new RunTaskJob($task, $now);
5757

5858
if (!$now) {
5959
$this->dispatcher->dispatch($job->delay($task->time_offset));

resources/scripts/components/server/schedules/ScheduleEditContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export default () => {
161161
onDeleted={() => history.push(`/server/${id}/schedules`)}
162162
/>
163163
</Can>
164-
{schedule.isActive && schedule.tasks.length > 0 &&
164+
{schedule.tasks.length > 0 &&
165165
<Can action={'schedule.update'}>
166166
<RunScheduleButton schedule={schedule}/>
167167
</Can>

tests/Integration/Api/Client/Server/Schedule/ExecuteScheduleTest.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,6 @@ public function testScheduleIsExecutedRightAway(array $permissions)
5151
});
5252
}
5353

54-
/**
55-
* Test that the schedule is not executed if it is not currently active.
56-
*/
57-
public function testScheduleIsNotExecutedIfNotActive()
58-
{
59-
[$user, $server] = $this->generateTestAccount();
60-
61-
/** @var \Pterodactyl\Models\Schedule $schedule */
62-
$schedule = Schedule::factory()->create([
63-
'server_id' => $server->id,
64-
'is_active' => false,
65-
]);
66-
67-
$response = $this->actingAs($user)->postJson($this->link($schedule, '/execute'));
68-
69-
$response->assertStatus(Response::HTTP_BAD_REQUEST);
70-
$response->assertJsonPath('errors.0.code', 'BadRequestHttpException');
71-
$response->assertJsonPath('errors.0.detail', 'Cannot trigger schedule exection for a schedule that is not currently active.');
72-
}
73-
7454
/**
7555
* Test that a user without the schedule update permission cannot execute it.
7656
*/

0 commit comments

Comments
 (0)