2024-06-21 18:45:16 -04:00
|
|
|
<?php
|
|
|
|
|
2024-11-03 02:18:17 -05:00
|
|
|
namespace App\Console;
|
2024-06-21 18:45:16 -04:00
|
|
|
|
2024-11-03 02:18:17 -05:00
|
|
|
use App\Console\Commands\Egg\CheckEggUpdatesCommand;
|
|
|
|
use App\Console\Commands\Maintenance\CleanServiceBackupFilesCommand;
|
|
|
|
use App\Console\Commands\Maintenance\PruneImagesCommand;
|
|
|
|
use App\Console\Commands\Maintenance\PruneOrphanedBackupsCommand;
|
|
|
|
use App\Console\Commands\Schedule\ProcessRunnableCommand;
|
|
|
|
use App\Jobs\NodeStatistics;
|
|
|
|
use App\Models\ActivityLog;
|
|
|
|
use App\Models\Webhook;
|
2024-06-21 18:45:16 -04:00
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
|
|
use Illuminate\Database\Console\PruneCommand;
|
|
|
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
|
|
|
|
|
|
|
class Kernel extends ConsoleKernel
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Register the commands for the application.
|
|
|
|
*/
|
|
|
|
protected function commands(): void
|
|
|
|
{
|
|
|
|
$this->load(__DIR__ . '/Commands');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define the application's command schedule.
|
|
|
|
*/
|
|
|
|
protected function schedule(Schedule $schedule): void
|
|
|
|
{
|
|
|
|
// https://laravel.com/docs/10.x/upgrade#redis-cache-tags
|
|
|
|
$schedule->command('cache:prune-stale-tags')->hourly();
|
|
|
|
|
|
|
|
// Execute scheduled commands for servers every minute, as if there was a normal cron running.
|
|
|
|
$schedule->command(ProcessRunnableCommand::class)->everyMinute()->withoutOverlapping();
|
2024-11-03 02:18:17 -05:00
|
|
|
|
2024-06-21 18:45:16 -04:00
|
|
|
$schedule->command(CleanServiceBackupFilesCommand::class)->daily();
|
2024-11-03 02:18:17 -05:00
|
|
|
$schedule->command(PruneImagesCommand::class)->daily();
|
|
|
|
$schedule->command(CheckEggUpdatesCommand::class)->hourly();
|
|
|
|
|
|
|
|
$schedule->job(new NodeStatistics())->everyFiveSeconds()->withoutOverlapping();
|
2024-06-21 18:45:16 -04:00
|
|
|
|
|
|
|
if (config('backups.prune_age')) {
|
|
|
|
// Every 30 minutes, run the backup pruning command so that any abandoned backups can be deleted.
|
|
|
|
$schedule->command(PruneOrphanedBackupsCommand::class)->everyThirtyMinutes();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config('activity.prune_days')) {
|
|
|
|
$schedule->command(PruneCommand::class, ['--model' => [ActivityLog::class]])->daily();
|
|
|
|
}
|
|
|
|
|
2024-11-03 02:18:17 -05:00
|
|
|
if (config('panel.webhook.prune_days')) {
|
|
|
|
$schedule->command(PruneCommand::class, ['--model' => [Webhook::class]])->daily();
|
2024-06-21 18:45:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* I wonder what this does.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
|
|
*/
|
|
|
|
private function registerTelemetry(Schedule $schedule): void
|
|
|
|
{
|
|
|
|
$settingsRepository = app()->make(SettingsRepository::class);
|
|
|
|
|
|
|
|
$uuid = $settingsRepository->get('app:telemetry:uuid');
|
|
|
|
if (is_null($uuid)) {
|
|
|
|
$uuid = Uuid::uuid4()->toString();
|
|
|
|
$settingsRepository->set('app:telemetry:uuid', $uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate a fixed time to run the data push at, this will be the same time every day.
|
|
|
|
$time = hexdec(str_replace('-', '', substr($uuid, 27))) % 1440;
|
|
|
|
$hour = floor($time / 60);
|
|
|
|
$minute = $time % 60;
|
|
|
|
|
|
|
|
// Run the telemetry collector.
|
|
|
|
$schedule->call(app()->make(TelemetryCollectionService::class))->description('Collect Telemetry')->dailyAt("$hour:$minute");
|
|
|
|
}
|
|
|
|
}
|