2023-03-17 14:33:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Console;
|
|
|
|
|
|
2024-08-06 12:36:56 +00:00
|
|
|
use App\Jobs\CheckForUpdatesJob;
|
2024-10-21 10:06:13 +00:00
|
|
|
use App\Jobs\CheckHelperImageJob;
|
2025-11-13 12:38:57 +00:00
|
|
|
use App\Jobs\CheckTraefikVersionJob;
|
2023-08-15 12:11:38 +00:00
|
|
|
use App\Jobs\CleanupInstanceStuffsJob;
|
2025-12-08 16:15:52 +00:00
|
|
|
use App\Jobs\CleanupOrphanedPreviewContainersJob;
|
2025-09-01 14:13:55 +00:00
|
|
|
use App\Jobs\PullChangelog;
|
2024-05-30 10:56:29 +00:00
|
|
|
use App\Jobs\PullTemplatesFromCDN;
|
2025-02-05 21:11:10 +00:00
|
|
|
use App\Jobs\RegenerateSslCertJob;
|
2025-07-12 12:44:52 +00:00
|
|
|
use App\Jobs\ScheduledJobManager;
|
2025-08-22 09:50:56 +00:00
|
|
|
use App\Jobs\ServerManagerJob;
|
2024-08-05 18:05:38 +00:00
|
|
|
use App\Jobs\UpdateCoolifyJob;
|
2024-11-02 11:38:22 +00:00
|
|
|
use App\Models\InstanceSettings;
|
2023-03-17 14:33:48 +00:00
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
|
|
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
|
|
|
|
|
|
|
|
|
class Kernel extends ConsoleKernel
|
|
|
|
|
{
|
2024-11-14 09:56:56 +00:00
|
|
|
private Schedule $scheduleInstance;
|
|
|
|
|
|
2024-11-02 11:38:22 +00:00
|
|
|
private InstanceSettings $settings;
|
|
|
|
|
|
2024-11-06 14:16:12 +00:00
|
|
|
private string $updateCheckFrequency;
|
|
|
|
|
|
|
|
|
|
private string $instanceTimezone;
|
|
|
|
|
|
2023-03-17 14:33:48 +00:00
|
|
|
protected function schedule(Schedule $schedule): void
|
|
|
|
|
{
|
2024-11-14 09:56:56 +00:00
|
|
|
$this->scheduleInstance = $schedule;
|
2024-11-02 11:38:22 +00:00
|
|
|
$this->settings = instanceSettings();
|
2024-11-06 14:16:12 +00:00
|
|
|
$this->updateCheckFrequency = $this->settings->update_check_frequency ?: '0 * * * *';
|
2024-11-14 09:56:56 +00:00
|
|
|
|
2024-11-06 14:16:12 +00:00
|
|
|
$this->instanceTimezone = $this->settings->instance_timezone ?: config('app.timezone');
|
2024-08-05 14:31:41 +00:00
|
|
|
|
2024-11-14 09:56:56 +00:00
|
|
|
if (validate_timezone($this->instanceTimezone) === false) {
|
|
|
|
|
$this->instanceTimezone = config('app.timezone');
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 22:38:31 +00:00
|
|
|
// $this->scheduleInstance->job(new CleanupStaleMultiplexedConnections)->hourly();
|
2026-02-25 11:07:29 +00:00
|
|
|
$this->scheduleInstance->command('cleanup:redis --clear-locks')->daily();
|
2024-09-08 17:37:00 +00:00
|
|
|
|
2023-08-27 13:23:47 +00:00
|
|
|
if (isDev()) {
|
2023-10-26 09:38:37 +00:00
|
|
|
// Instance Jobs
|
2024-11-14 09:56:56 +00:00
|
|
|
$this->scheduleInstance->command('horizon:snapshot')->everyMinute();
|
|
|
|
|
$this->scheduleInstance->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer();
|
|
|
|
|
$this->scheduleInstance->job(new CheckHelperImageJob)->everyTenMinutes()->onOneServer();
|
2024-11-03 08:02:14 +00:00
|
|
|
|
2023-10-26 09:38:37 +00:00
|
|
|
// Server Jobs
|
2025-08-22 09:50:56 +00:00
|
|
|
$this->scheduleInstance->job(new ServerManagerJob)->everyMinute()->onOneServer();
|
2024-11-03 08:02:14 +00:00
|
|
|
|
2025-07-12 12:44:52 +00:00
|
|
|
// Scheduled Jobs (Backups & Tasks)
|
|
|
|
|
$this->scheduleInstance->job(new ScheduledJobManager)->everyMinute()->onOneServer();
|
2024-11-03 08:02:14 +00:00
|
|
|
|
2024-11-14 09:56:56 +00:00
|
|
|
$this->scheduleInstance->command('uploads:clear')->everyTwoMinutes();
|
2024-09-08 17:37:00 +00:00
|
|
|
|
2023-06-06 06:43:01 +00:00
|
|
|
} else {
|
2023-10-26 09:38:37 +00:00
|
|
|
// Instance Jobs
|
2024-11-14 09:56:56 +00:00
|
|
|
$this->scheduleInstance->command('horizon:snapshot')->everyFiveMinutes();
|
|
|
|
|
$this->scheduleInstance->command('cleanup:unreachable-servers')->daily()->onOneServer();
|
|
|
|
|
|
|
|
|
|
$this->scheduleInstance->job(new PullTemplatesFromCDN)->cron($this->updateCheckFrequency)->timezone($this->instanceTimezone)->onOneServer();
|
2025-09-01 14:13:55 +00:00
|
|
|
$this->scheduleInstance->job(new PullChangelog)->cron($this->updateCheckFrequency)->timezone($this->instanceTimezone)->onOneServer();
|
2024-11-14 09:56:56 +00:00
|
|
|
|
|
|
|
|
$this->scheduleInstance->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer();
|
|
|
|
|
$this->scheduleUpdates();
|
2023-10-26 09:38:37 +00:00
|
|
|
|
|
|
|
|
// Server Jobs
|
2025-08-22 09:50:56 +00:00
|
|
|
$this->scheduleInstance->job(new ServerManagerJob)->everyMinute()->onOneServer();
|
2024-11-03 08:02:14 +00:00
|
|
|
|
2024-11-14 09:56:56 +00:00
|
|
|
$this->pullImages();
|
2024-11-03 08:02:14 +00:00
|
|
|
|
2025-07-12 12:44:52 +00:00
|
|
|
// Scheduled Jobs (Backups & Tasks)
|
|
|
|
|
$this->scheduleInstance->job(new ScheduledJobManager)->everyMinute()->onOneServer();
|
2024-03-04 11:17:33 +00:00
|
|
|
|
2025-02-05 21:11:10 +00:00
|
|
|
$this->scheduleInstance->job(new RegenerateSslCertJob)->twiceDaily();
|
|
|
|
|
|
2025-11-13 12:38:57 +00:00
|
|
|
$this->scheduleInstance->job(new CheckTraefikVersionJob)->weekly()->sundays()->at('00:00')->timezone($this->instanceTimezone)->onOneServer();
|
|
|
|
|
|
2024-11-14 09:56:56 +00:00
|
|
|
$this->scheduleInstance->command('cleanup:database --yes')->daily();
|
|
|
|
|
$this->scheduleInstance->command('uploads:clear')->everyTwoMinutes();
|
2025-12-08 16:15:52 +00:00
|
|
|
|
|
|
|
|
// Cleanup orphaned PR preview containers daily
|
|
|
|
|
$this->scheduleInstance->job(new CleanupOrphanedPreviewContainersJob)->daily()->onOneServer();
|
2023-10-26 09:38:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-11-14 09:56:56 +00:00
|
|
|
private function pullImages(): void
|
2023-10-26 09:38:37 +00:00
|
|
|
{
|
2024-11-14 09:56:56 +00:00
|
|
|
$this->scheduleInstance->job(new CheckHelperImageJob)
|
2024-11-06 14:16:12 +00:00
|
|
|
->cron($this->updateCheckFrequency)
|
|
|
|
|
->timezone($this->instanceTimezone)
|
2024-09-19 09:24:21 +00:00
|
|
|
->onOneServer();
|
2024-08-05 14:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-14 09:56:56 +00:00
|
|
|
private function scheduleUpdates(): void
|
2024-08-05 14:31:41 +00:00
|
|
|
{
|
2024-11-14 09:56:56 +00:00
|
|
|
$this->scheduleInstance->job(new CheckForUpdatesJob)
|
2024-11-06 14:16:12 +00:00
|
|
|
->cron($this->updateCheckFrequency)
|
|
|
|
|
->timezone($this->instanceTimezone)
|
2024-08-16 14:01:41 +00:00
|
|
|
->onOneServer();
|
2024-08-05 14:31:41 +00:00
|
|
|
|
2024-11-02 11:38:22 +00:00
|
|
|
if ($this->settings->is_auto_update_enabled) {
|
|
|
|
|
$autoUpdateFrequency = $this->settings->auto_update_frequency;
|
2024-11-14 09:56:56 +00:00
|
|
|
$this->scheduleInstance->job(new UpdateCoolifyJob)
|
2024-08-16 14:01:41 +00:00
|
|
|
->cron($autoUpdateFrequency)
|
2024-11-06 14:16:12 +00:00
|
|
|
->timezone($this->instanceTimezone)
|
2024-08-16 14:01:41 +00:00
|
|
|
->onOneServer();
|
2023-09-29 12:26:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-03-17 14:33:48 +00:00
|
|
|
protected function commands(): void
|
|
|
|
|
{
|
2024-08-26 13:26:08 +00:00
|
|
|
$this->load(__DIR__.'/Commands');
|
2023-03-17 14:33:48 +00:00
|
|
|
|
|
|
|
|
require base_path('routes/console.php');
|
|
|
|
|
}
|
2024-08-26 13:26:08 +00:00
|
|
|
}
|