Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Console/Kernel.php
7432 views
1
<?php
2
3
namespace Pterodactyl\Console;
4
5
use Ramsey\Uuid\Uuid;
6
use Pterodactyl\Models\ActivityLog;
7
use Illuminate\Console\Scheduling\Schedule;
8
use Illuminate\Database\Console\PruneCommand;
9
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
10
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
11
use Pterodactyl\Services\Telemetry\TelemetryCollectionService;
12
use Pterodactyl\Console\Commands\Schedule\ProcessRunnableCommand;
13
use Pterodactyl\Console\Commands\Maintenance\PruneOrphanedBackupsCommand;
14
use Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand;
15
16
class Kernel extends ConsoleKernel
17
{
18
/**
19
* Register the commands for the application.
20
*/
21
protected function commands(): void
22
{
23
$this->load(__DIR__ . '/Commands');
24
}
25
26
/**
27
* Define the application's command schedule.
28
*/
29
protected function schedule(Schedule $schedule): void
30
{
31
// https://laravel.com/docs/10.x/upgrade#redis-cache-tags
32
$schedule->command('cache:prune-stale-tags')->hourly();
33
34
// Execute scheduled commands for servers every minute, as if there was a normal cron running.
35
$schedule->command(ProcessRunnableCommand::class)->everyMinute()->withoutOverlapping();
36
$schedule->command(CleanServiceBackupFilesCommand::class)->daily();
37
38
if (config('backups.prune_age')) {
39
// Every 30 minutes, run the backup pruning command so that any abandoned backups can be deleted.
40
$schedule->command(PruneOrphanedBackupsCommand::class)->everyThirtyMinutes();
41
}
42
43
if (config('activity.prune_days')) {
44
$schedule->command(PruneCommand::class, ['--model' => [ActivityLog::class]])->daily();
45
}
46
47
if (config('pterodactyl.telemetry.enabled')) {
48
$this->registerTelemetry($schedule);
49
}
50
}
51
52
/**
53
* I wonder what this does.
54
*
55
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
56
* @throws \Illuminate\Contracts\Container\BindingResolutionException
57
*/
58
private function registerTelemetry(Schedule $schedule): void
59
{
60
$settingsRepository = app()->make(SettingsRepository::class);
61
62
$uuid = $settingsRepository->get('app:telemetry:uuid');
63
if (is_null($uuid)) {
64
$uuid = Uuid::uuid4()->toString();
65
$settingsRepository->set('app:telemetry:uuid', $uuid);
66
}
67
68
// Calculate a fixed time to run the data push at, this will be the same time every day.
69
$time = hexdec(str_replace('-', '', substr($uuid, 27))) % 1440;
70
$hour = floor($time / 60);
71
$minute = $time % 60;
72
73
// Run the telemetry collector.
74
$schedule->call(app()->make(TelemetryCollectionService::class))->description('Collect Telemetry')->dailyAt("$hour:$minute");
75
}
76
}
77
78