File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed
Console/Commands/Schedule
tests/Integration/Jobs/Schedule Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 77use Illuminate \Console \Command ;
88use Pterodactyl \Models \Schedule ;
99use Illuminate \Support \Facades \Log ;
10+ use Illuminate \Database \Eloquent \Builder ;
1011use Pterodactyl \Services \Schedules \ProcessScheduleService ;
1112
1213class ProcessRunnableCommand extends Command
@@ -26,7 +27,9 @@ class ProcessRunnableCommand extends Command
2627 */
2728 public function handle ()
2829 {
29- $ schedules = Schedule::query ()->with ('tasks ' )
30+ $ schedules = Schedule::query ()
31+ ->with ('tasks ' )
32+ ->whereRelation ('server ' , fn (Builder $ builder ) => $ builder ->whereNull ('status ' ))
3033 ->where ('is_active ' , true )
3134 ->where ('is_processing ' , false )
3235 ->whereRaw ('next_run_at <= NOW() ' )
Original file line number Diff line number Diff line change @@ -61,6 +61,16 @@ public function handle(
6161 }
6262
6363 $ server = $ this ->task ->server ;
64+ // If we made it to this point and the server status is not null it means the
65+ // server was likely suspended or marked as reinstalling after the schedule
66+ // was queued up. Just end the task right now — this should be a very rare
67+ // condition.
68+ if (!is_null ($ server ->status )) {
69+ $ this ->failed ();
70+
71+ return ;
72+ }
73+
6474 // Perform the provided task against the daemon.
6575 try {
6676 switch ($ this ->task ->action ) {
Original file line number Diff line number Diff line change 33namespace Pterodactyl \Tests \Integration \Jobs \Schedule ;
44
55use Mockery ;
6+ use Carbon \Carbon ;
7+ use DateTimeInterface ;
68use Carbon \CarbonImmutable ;
79use GuzzleHttp \Psr7 \Request ;
810use Pterodactyl \Models \Task ;
@@ -146,6 +148,36 @@ public function testExceptionDuringRunIsHandledCorrectly(bool $continueOnFailure
146148 }
147149 }
148150
151+ /**
152+ * Test that a schedule is not executed if the server is suspended.
153+ *
154+ * @see https://github.com/pterodactyl/panel/issues/4008
155+ */
156+ public function testTaskIsNotRunIfServerIsSuspended ()
157+ {
158+ $ server = $ this ->createServerModel ([
159+ 'status ' => Server::STATUS_SUSPENDED ,
160+ ]);
161+
162+ $ schedule = Schedule::factory ()->for ($ server )->create ([
163+ 'last_run_at ' => Carbon::now ()->subHour (),
164+ ]);
165+
166+ $ task = Task::factory ()->for ($ schedule )->create ([
167+ 'action ' => Task::ACTION_POWER ,
168+ 'payload ' => 'start ' ,
169+ ]);
170+
171+ Bus::dispatchNow (new RunTaskJob ($ task ));
172+
173+ $ task ->refresh ();
174+ $ schedule ->refresh ();
175+
176+ $ this ->assertFalse ($ task ->is_queued );
177+ $ this ->assertFalse ($ schedule ->is_processing );
178+ $ this ->assertTrue (Carbon::now ()->isSameAs (DateTimeInterface::ATOM , $ schedule ->last_run_at ));
179+ }
180+
149181 /**
150182 * @return array
151183 */
You can’t perform that action at this time.
0 commit comments