This commit is contained in:
Andras Bacsai
2024-08-07 09:50:29 +02:00
parent 869f0878c2
commit e4c3d61b76
4 changed files with 18 additions and 16 deletions

View File

@@ -19,6 +19,7 @@ class CleanupDatabase extends Command
echo "Running database cleanup in dry-run mode...\n"; echo "Running database cleanup in dry-run mode...\n";
} }
if (isCloud()) { if (isCloud()) {
// Later on we can increase this to 180 days or dynamically set
$keep_days = 60; $keep_days = 60;
} else { } else {
$keep_days = 60; $keep_days = 60;

View File

@@ -34,24 +34,24 @@ class Kernel extends ConsoleKernel
// Instance Jobs // Instance Jobs
$schedule->command('horizon:snapshot')->everyMinute(); $schedule->command('horizon:snapshot')->everyMinute();
$schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer(); $schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer();
$schedule->job(new PullTemplatesFromCDN)->cron($settings->update_check_frequency)->onOneServer();
// Server Jobs // Server Jobs
$this->check_scheduled_backups($schedule); $this->check_scheduled_backups($schedule);
$this->checkResourcesNew($schedule); $this->check_resources($schedule);
$this->check_scheduled_tasks($schedule); $this->check_scheduled_tasks($schedule);
$schedule->command('uploads:clear')->everyTwoMinutes(); $schedule->command('uploads:clear')->everyTwoMinutes();
} else { } else {
// Instance Jobs // Instance Jobs
$schedule->command('horizon:snapshot')->everyFiveMinutes(); $schedule->command('horizon:snapshot')->everyFiveMinutes();
$schedule->command('cleanup:unreachable-servers')->daily(); $schedule->command('cleanup:unreachable-servers')->daily();
$this->scheduleUpdates($schedule);
$schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->onOneServer(); $schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->onOneServer();
$schedule->job(new PullTemplatesFromCDN)->cron($settings->update_check_frequency)->onOneServer(); $schedule->job(new PullTemplatesFromCDN)->cron($settings->update_check_frequency)->onOneServer();
$schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer(); $schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer();
$this->schedule_updates($schedule);
// Server Jobs // Server Jobs
$this->check_scheduled_backups($schedule); $this->check_scheduled_backups($schedule);
$this->checkResourcesNew($schedule); $this->check_resources($schedule);
$this->pull_images($schedule); $this->pull_images($schedule);
$this->check_scheduled_tasks($schedule); $this->check_scheduled_tasks($schedule);
@@ -72,7 +72,7 @@ class Kernel extends ConsoleKernel
} }
} }
private function scheduleUpdates($schedule) private function schedule_updates($schedule)
{ {
$settings = InstanceSettings::get(); $settings = InstanceSettings::get();
@@ -85,7 +85,7 @@ class Kernel extends ConsoleKernel
} }
} }
private function checkResourcesNew($schedule) private function check_resources($schedule)
{ {
if (isCloud()) { if (isCloud()) {
$servers = $this->all_servers->whereNotNull('team.subscription')->where('team.subscription.stripe_trial_already_ended', false)->where('ip', '!=', '1.2.3.4'); $servers = $this->all_servers->whereNotNull('team.subscription')->where('team.subscription.stripe_trial_already_ended', false)->where('ip', '!=', '1.2.3.4');

View File

@@ -22,15 +22,16 @@ class PullTemplatesFromCDN implements ShouldBeEncrypted, ShouldQueue
public function handle(): void public function handle(): void
{ {
try { try {
if (! isDev()) { if (isDev() || isCloud()) {
ray('PullTemplatesAndVersions service-templates'); return;
$response = Http::retry(3, 1000)->get(config('constants.services.official')); }
if ($response->successful()) { ray('PullTemplatesAndVersions service-templates');
$services = $response->json(); $response = Http::retry(3, 1000)->get(config('constants.services.official'));
File::put(base_path('templates/service-templates.json'), json_encode($services)); if ($response->successful()) {
} else { $services = $response->json();
send_internal_notification('PullTemplatesAndVersions failed with: '.$response->status().' '.$response->body()); File::put(base_path('templates/service-templates.json'), json_encode($services));
} } else {
send_internal_notification('PullTemplatesAndVersions failed with: '.$response->status().' '.$response->body());
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
send_internal_notification('PullTemplatesAndVersions failed with: '.$e->getMessage()); send_internal_notification('PullTemplatesAndVersions failed with: '.$e->getMessage());

View File

@@ -505,7 +505,7 @@ function get_service_templates(bool $force = false): Collection
{ {
if ($force) { if ($force) {
try { try {
$response = Http::retry(3, 50)->get(config('constants.services.official')); $response = Http::retry(3, 1000)->get(config('constants.services.official'));
if ($response->failed()) { if ($response->failed()) {
return collect([]); return collect([]);
} }