11<?php
2- /**
3- * Pterodactyl - Panel
4- * Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5- *
6- * This software is licensed under the terms of the MIT license.
7- * https://opensource.org/licenses/MIT
8- */
92
103namespace Pterodactyl \Console \Commands \Schedule ;
114
12- use Cake \Chronos \Chronos ;
135use Illuminate \Console \Command ;
14- use Illuminate \ Support \ Collection ;
6+ use Pterodactyl \ Models \ Schedule ;
157use Pterodactyl \Services \Schedules \ProcessScheduleService ;
16- use Pterodactyl \Contracts \Repository \ScheduleRepositoryInterface ;
178
189class ProcessRunnableCommand extends Command
1910{
2011 /**
2112 * @var string
2213 */
23- protected $ description = 'Process schedules in the database and determine which are ready to run. ' ;
24-
25- /**
26- * @var \Pterodactyl\Services\Schedules\ProcessScheduleService
27- */
28- protected $ processScheduleService ;
29-
30- /**
31- * @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface
32- */
33- protected $ repository ;
14+ protected $ signature = 'p:schedule:process ' ;
3415
3516 /**
3617 * @var string
3718 */
38- protected $ signature = 'p:schedule:process ' ;
19+ protected $ description = 'Process schedules in the database and determine which are ready to run. ' ;
3920
4021 /**
41- * ProcessRunnableCommand constructor.
22+ * Handle command execution.
23+ *
24+ * @param \Pterodactyl\Services\Schedules\ProcessScheduleService $service
4225 *
43- * @param \Pterodactyl\Services\Schedules\ProcessScheduleService $processScheduleService
44- * @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
26+ * @throws \Throwable
4527 */
46- public function __construct (ProcessScheduleService $ processScheduleService , ScheduleRepositoryInterface $ repository )
28+ public function handle (ProcessScheduleService $ service )
4729 {
48- parent ::__construct ();
30+ $ schedules = Schedule::query ()->with ('tasks ' )
31+ ->where ('is_active ' , true )
32+ ->where ('is_processing ' , false )
33+ ->whereRaw ('next_run_at <= NOW() ' )
34+ ->get ();
4935
50- $ this ->processScheduleService = $ processScheduleService ;
51- $ this ->repository = $ repository ;
52- }
53-
54- /**
55- * Handle command execution.
56- */
57- public function handle ()
58- {
59- $ schedules = $ this ->repository ->getSchedulesToProcess (Chronos::now ()->toAtomString ());
6036 if ($ schedules ->count () < 1 ) {
6137 $ this ->line ('There are no scheduled tasks for servers that need to be run. ' );
6238
6339 return ;
6440 }
6541
6642 $ bar = $ this ->output ->createProgressBar (count ($ schedules ));
67- $ schedules -> each ( function ($ schedule ) use ( $ bar ) {
68- if ($ schedule ->tasks instanceof Collection && count ( $ schedule -> tasks ) > 0 ) {
69- $ this -> processScheduleService ->handle ($ schedule );
43+ foreach ($ schedules as $ schedule ) {
44+ if ($ schedule ->tasks -> isNotEmpty () ) {
45+ $ service ->handle ($ schedule );
7046
7147 if ($ this ->input ->isInteractive ()) {
7248 $ bar ->clear ();
@@ -79,7 +55,7 @@ public function handle()
7955
8056 $ bar ->advance ();
8157 $ bar ->display ();
82- });
58+ }
8359
8460 $ this ->line ('' );
8561 }
0 commit comments