From 7b731e93c6bc50f24775e7439bbfd911eb5c29bd Mon Sep 17 00:00:00 2001 From: "Victor B." Date: Sat, 22 Jun 2024 00:45:16 +0200 Subject: [PATCH] feat `core`: KernelExtensions class for ivy --- .../Console/KernelExtensions.php | 11 +++ app/Console/Kernel.php | 79 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 app/BlueprintFramework/Console/KernelExtensions.php create mode 100644 app/Console/Kernel.php diff --git a/app/BlueprintFramework/Console/KernelExtensions.php b/app/BlueprintFramework/Console/KernelExtensions.php new file mode 100644 index 0000000..973faed --- /dev/null +++ b/app/BlueprintFramework/Console/KernelExtensions.php @@ -0,0 +1,11 @@ +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(); + $schedule->command(CleanServiceBackupFilesCommand::class)->daily(); + + 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(); + } + + if (config('pterodactyl.telemetry.enabled')) { + $this->registerTelemetry($schedule); + } + + KernelExtensions::schedules($schedule); + } + + /** + * 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"); + } +}