Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"

HEALTH_CHECK_INTERVAL=24
CLEANUP_SITE_DELAY=7
60 changes: 60 additions & 0 deletions app/Console/Commands/CleanupSitesList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App\Console\Commands;

use App\Models\Site;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Collection;

class CleanupSitesList extends Command
{
protected int $totalDeleted = 0;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:cleanup-sites-list';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Cleanup sites that are too old and haven\'t been seen for a while' ;

/**
* Execute the console command.
*/
public function handle(): int
{
$this->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;
}
}
3 changes: 2 additions & 1 deletion config/autoupdates.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

return [
'healthcheck_interval' => env('HEALTH_CHECK_INTERVAL', 24)
'healthcheck_interval' => env('HEALTH_CHECK_INTERVAL', 24),
'cleanup_site_delay' => env('CLEANUP_SITE_DELAY', 7),
];
Loading