command('horizon:snapshot')->everyMinute(); $schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer(); // $schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer(); // Server Jobs $this->check_scheduled_backups($schedule); $this->check_resources($schedule); $this->check_scheduled_backups($schedule); $this->pull_helper_image($schedule); } else { // Instance Jobs $schedule->command('horizon:snapshot')->everyFiveMinutes(); $schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer(); // $schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer(); // Server Jobs $this->instance_auto_update($schedule); $this->check_scheduled_backups($schedule); $this->check_resources($schedule); $this->pull_helper_image($schedule); } } private function pull_helper_image($schedule) { $servers = Server::all()->where('settings.is_usable', true)->where('settings.is_reachable', true)->where('ip', '!=', '1.2.3.4'); foreach ($servers as $server) { $schedule->job(new PullHelperImageJob($server))->everyTenMinutes()->onOneServer(); } } private function check_resources($schedule) { if (isCloud()) { $servers = Server::all()->whereNotNull('team.subscription')->where('team.subscription.stripe_trial_already_ended', false)->where('ip', '!=', '1.2.3.4'); $own = Team::find(0)->servers; $servers = $servers->merge($own); } else { $servers = Server::all()->where('ip', '!=', '1.2.3.4'); } foreach ($servers as $server) { $schedule->job(new ServerStatusJob($server))->everyTenMinutes()->onOneServer(); $schedule->job(new ContainerStatusJob($server))->everyMinute()->onOneServer(); if ($server->isLogDrainEnabled()) { $schedule->job(new CheckLogDrainContainerJob($server))->everyMinute()->onOneServer(); } } } private function instance_auto_update($schedule) { if (isDev()) { return; } $settings = InstanceSettings::get(); if ($settings->is_auto_update_enabled) { $schedule->job(new InstanceAutoUpdateJob)->everyTenMinutes()->onOneServer(); } } private function check_scheduled_backups($schedule) { $scheduled_backups = ScheduledDatabaseBackup::all(); if ($scheduled_backups->isEmpty()) { ray('no scheduled backups'); return; } foreach ($scheduled_backups as $scheduled_backup) { if (!$scheduled_backup->enabled) { continue; } if (is_null(data_get($scheduled_backup, 'database'))) { ray('database not found'); $scheduled_backup->delete(); continue; } if (isset(VALID_CRON_STRINGS[$scheduled_backup->frequency])) { $scheduled_backup->frequency = VALID_CRON_STRINGS[$scheduled_backup->frequency]; } $schedule->job(new DatabaseBackupJob( backup: $scheduled_backup ))->cron($scheduled_backup->frequency)->onOneServer(); } } protected function commands(): void { $this->load(__DIR__ . '/Commands'); require base_path('routes/console.php'); } }