2023-03-17 15:33:48 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console;
|
|
|
|
|
2023-09-02 15:53:12 +02:00
|
|
|
use App\Jobs\ApplicationContainerStatusJob;
|
2023-07-14 11:27:08 +02:00
|
|
|
use App\Jobs\CheckResaleLicenseJob;
|
2023-08-15 14:11:38 +02:00
|
|
|
use App\Jobs\CleanupInstanceStuffsJob;
|
2023-08-10 15:52:54 +02:00
|
|
|
use App\Jobs\DatabaseBackupJob;
|
2023-09-02 15:53:12 +02:00
|
|
|
use App\Jobs\DatabaseContainerStatusJob;
|
2023-08-08 11:51:36 +02:00
|
|
|
use App\Jobs\DockerCleanupJob;
|
2023-05-25 14:23:49 +02:00
|
|
|
use App\Jobs\InstanceAutoUpdateJob;
|
2023-07-07 15:50:36 +02:00
|
|
|
use App\Jobs\ProxyCheckJob;
|
2023-08-16 17:18:50 +02:00
|
|
|
use App\Jobs\ResourceStatusJob;
|
2023-09-02 15:53:12 +02:00
|
|
|
use App\Models\Application;
|
2023-09-01 16:30:50 +02:00
|
|
|
use App\Models\InstanceSettings;
|
2023-08-08 17:28:36 +02:00
|
|
|
use App\Models\ScheduledDatabaseBackup;
|
2023-09-02 15:53:12 +02:00
|
|
|
use App\Models\StandalonePostgresql;
|
2023-03-17 15:33:48 +01:00
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
|
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
|
|
|
|
|
|
|
class Kernel extends ConsoleKernel
|
|
|
|
{
|
|
|
|
protected function schedule(Schedule $schedule): void
|
|
|
|
{
|
2023-08-27 15:23:47 +02:00
|
|
|
if (isDev()) {
|
2023-06-06 08:43:01 +02:00
|
|
|
$schedule->command('horizon:snapshot')->everyMinute();
|
2023-09-02 15:53:12 +02:00
|
|
|
// $schedule->job(new ResourceStatusJob)->everyMinute();
|
2023-07-14 13:03:58 +02:00
|
|
|
$schedule->job(new ProxyCheckJob)->everyFiveMinutes();
|
2023-08-15 14:11:38 +02:00
|
|
|
$schedule->job(new CleanupInstanceStuffsJob)->everyMinute();
|
2023-07-14 11:33:08 +02:00
|
|
|
// $schedule->job(new CheckResaleLicenseJob)->hourly();
|
2023-09-01 10:11:00 +02:00
|
|
|
$schedule->job(new DockerCleanupJob)->everyOddHour();
|
2023-06-06 08:43:01 +02:00
|
|
|
} else {
|
|
|
|
$schedule->command('horizon:snapshot')->everyFiveMinutes();
|
2023-09-01 16:30:50 +02:00
|
|
|
$schedule->job(new CleanupInstanceStuffsJob)->everyTenMinutes()->onOneServer();
|
2023-09-02 15:53:12 +02:00
|
|
|
// $schedule->job(new ResourceStatusJob)->everyMinute()->onOneServer();
|
2023-08-28 11:43:01 +02:00
|
|
|
$schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer();
|
|
|
|
$schedule->job(new ProxyCheckJob)->everyFiveMinutes()->onOneServer();
|
|
|
|
$schedule->job(new DockerCleanupJob)->everyTenMinutes()->onOneServer();
|
2023-06-06 08:43:01 +02:00
|
|
|
}
|
2023-09-01 16:30:50 +02:00
|
|
|
$this->instance_auto_update($schedule);
|
2023-08-08 17:28:36 +02:00
|
|
|
$this->check_scheduled_backups($schedule);
|
2023-09-02 15:53:12 +02:00
|
|
|
$this->check_resources($schedule);
|
|
|
|
}
|
|
|
|
private function check_resources($schedule)
|
|
|
|
{
|
|
|
|
$applications = Application::all();
|
|
|
|
foreach ($applications as $application) {
|
|
|
|
$schedule->job(new ApplicationContainerStatusJob($application))->everyMinute()->onOneServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
$postgresqls = StandalonePostgresql::all();
|
|
|
|
foreach ($postgresqls as $postgresql) {
|
|
|
|
$schedule->job(new DatabaseContainerStatusJob($postgresql))->everyMinute()->onOneServer();
|
|
|
|
}
|
2023-08-08 17:28:36 +02:00
|
|
|
}
|
2023-09-01 16:30:50 +02:00
|
|
|
private function instance_auto_update($schedule){
|
|
|
|
if (isDev()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$settings = InstanceSettings::get();
|
|
|
|
if ($settings->is_auto_update_enabled) {
|
|
|
|
$schedule->job(new InstanceAutoUpdateJob)->everyTenMinutes()->onOneServer();
|
|
|
|
}
|
|
|
|
}
|
2023-08-08 17:28:36 +02:00
|
|
|
private function check_scheduled_backups($schedule)
|
|
|
|
{
|
|
|
|
ray('check_scheduled_backups');
|
|
|
|
$scheduled_backups = ScheduledDatabaseBackup::all();
|
|
|
|
if ($scheduled_backups->isEmpty()) {
|
|
|
|
ray('no scheduled backups');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foreach ($scheduled_backups as $scheduled_backup) {
|
2023-08-16 17:18:50 +02:00
|
|
|
if (!$scheduled_backup->enabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-08-09 17:57:27 +02:00
|
|
|
if (isset(VALID_CRON_STRINGS[$scheduled_backup->frequency])) {
|
|
|
|
$scheduled_backup->frequency = VALID_CRON_STRINGS[$scheduled_backup->frequency];
|
|
|
|
}
|
2023-08-10 15:52:54 +02:00
|
|
|
$schedule->job(new DatabaseBackupJob(
|
2023-08-08 17:28:36 +02:00
|
|
|
backup: $scheduled_backup
|
2023-09-01 16:30:50 +02:00
|
|
|
))->cron($scheduled_backup->frequency)->onOneServer();
|
2023-08-08 17:28:36 +02:00
|
|
|
}
|
2023-03-17 15:33:48 +01:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-03-17 15:33:48 +01:00
|
|
|
protected function commands(): void
|
|
|
|
{
|
2023-04-28 09:00:47 +02:00
|
|
|
$this->load(__DIR__ . '/Commands');
|
2023-03-17 15:33:48 +01:00
|
|
|
|
|
|
|
require base_path('routes/console.php');
|
|
|
|
}
|
2023-07-14 11:27:08 +02:00
|
|
|
}
|