|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Pterodactyl - Panel |
|
4
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>. |
|
5
|
|
|
* |
|
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
8
|
|
|
* in the Software without restriction, including without limitation the rights |
|
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
11
|
|
|
* furnished to do so, subject to the following conditions: |
|
12
|
|
|
* |
|
13
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
14
|
|
|
* copies or substantial portions of the Software. |
|
15
|
|
|
* |
|
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
22
|
|
|
* SOFTWARE. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace Pterodactyl\Console\Commands; |
|
26
|
|
|
|
|
27
|
|
|
use Carbon; |
|
28
|
|
|
use Pterodactyl\Models\Task; |
|
29
|
|
|
use Illuminate\Console\Command; |
|
30
|
|
|
use Pterodactyl\Jobs\SendScheduledTask; |
|
31
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
|
32
|
|
|
|
|
33
|
|
|
class RunTasks extends Command |
|
34
|
|
|
{ |
|
35
|
|
|
use DispatchesJobs; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The name and signature of the console command. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $signature = 'pterodactyl:tasks'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The console command description. |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $description = 'Find and run scheduled tasks.'; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Create a new command instance. |
|
53
|
|
|
* |
|
54
|
|
|
* @return void |
|
|
|
|
|
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct() |
|
57
|
|
|
{ |
|
58
|
|
|
parent::__construct(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Execute the console command. |
|
63
|
|
|
* |
|
64
|
|
|
* @return mixed |
|
65
|
|
|
*/ |
|
66
|
|
|
public function handle() |
|
67
|
|
|
{ |
|
68
|
|
|
$tasks = Task::where('queued', false)->where('active', true)->where('next_run', '<=', Carbon::now()->toAtomString())->get(); |
|
69
|
|
|
|
|
70
|
|
|
$this->info(sprintf('Preparing to queue %d tasks.', count($tasks))); |
|
71
|
|
|
$bar = $this->output->createProgressBar(count($tasks)); |
|
72
|
|
|
|
|
73
|
|
|
foreach ($tasks as &$task) { |
|
74
|
|
|
$bar->advance(); |
|
75
|
|
|
$this->dispatch((new SendScheduledTask($task))->onQueue(config('pterodactyl.queues.low'))); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$bar->finish(); |
|
79
|
|
|
$this->info("\nFinished queuing tasks for running."); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.