diff --git a/.env.example b/.env.example index 5fb97bc..ce7f7fd 100644 --- a/.env.example +++ b/.env.example @@ -65,3 +65,4 @@ AWS_USE_PATH_STYLE_ENDPOINT=false VITE_APP_NAME="${APP_NAME}" HEALTH_CHECK_INTERVAL=24 +CLEANUP_SITE_DELAY=7 diff --git a/app/Console/Commands/CleanupSitesList.php b/app/Console/Commands/CleanupSitesList.php new file mode 100644 index 0000000..20819f8 --- /dev/null +++ b/app/Console/Commands/CleanupSitesList.php @@ -0,0 +1,60 @@ +output->writeln('Cleanup sites '); + + Site::query() + ->whereDate( + 'last_seen', + '<', + Carbon::now()->subDays((int) config('autoupdates.cleanup_site_delay')) // @phpstan-ignore-line + ) + ->chunkById( + 100, + function (Collection $chunk) { + // Show progress + $this->output->write('.'); + + $this->totalDeleted += $chunk->count(); + + // Push each site check to queue + $chunk->each(fn ($site) => $site->delete()); + } + ); + + // Result + $this->output->writeln(""); + $this->output->writeln('Deleted ' . $this->totalDeleted . ' Sites'); + + return Command::SUCCESS; + } +} diff --git a/config/autoupdates.php b/config/autoupdates.php index 8ca0839..c7bd1cf 100644 --- a/config/autoupdates.php +++ b/config/autoupdates.php @@ -1,5 +1,6 @@ env('HEALTH_CHECK_INTERVAL', 24) + 'healthcheck_interval' => env('HEALTH_CHECK_INTERVAL', 24), + 'cleanup_site_delay' => env('CLEANUP_SITE_DELAY', 7), ];