File tree Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -65,3 +65,4 @@ AWS_USE_PATH_STYLE_ENDPOINT=false
6565VITE_APP_NAME = " ${ APP_NAME } "
6666
6767HEALTH_CHECK_INTERVAL = 24
68+ CLEANUP_SITE_DELAY = 7
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Console \Commands ;
4+
5+ use App \Models \Site ;
6+ use Carbon \Carbon ;
7+ use Illuminate \Console \Command ;
8+ use Illuminate \Database \Eloquent \Collection ;
9+
10+ class CleanupSitesList extends Command
11+ {
12+ protected int $ totalDeleted = 0 ;
13+
14+ /**
15+ * The name and signature of the console command.
16+ *
17+ * @var string
18+ */
19+ protected $ signature = 'app:cleanup-sites-list ' ;
20+
21+ /**
22+ * The console command description.
23+ *
24+ * @var string
25+ */
26+ protected $ description = 'Cleanup sites that are too old and haven \'t been seen for a while ' ;
27+
28+ /**
29+ * Execute the console command.
30+ */
31+ public function handle (): int
32+ {
33+ $ this ->output ->writeln ('Cleanup sites ' );
34+
35+ Site::query ()
36+ ->whereDate (
37+ 'last_seen ' ,
38+ '< ' ,
39+ Carbon::now ()->subDays ((int ) config ('autoupdates.cleanup_site_delay ' )) // @phpstan-ignore-line
40+ )
41+ ->chunkById (
42+ 100 ,
43+ function (Collection $ chunk ) {
44+ // Show progress
45+ $ this ->output ->write ('. ' );
46+
47+ $ this ->totalDeleted += $ chunk ->count ();
48+
49+ // Push each site check to queue
50+ $ chunk ->each (fn ($ site ) => $ site ->delete ());
51+ }
52+ );
53+
54+ // Result
55+ $ this ->output ->writeln ("" );
56+ $ this ->output ->writeln ('Deleted ' . $ this ->totalDeleted . ' Sites ' );
57+
58+ return Command::SUCCESS ;
59+ }
60+ }
Original file line number Diff line number Diff line change 11<?php
22
33return [
4- 'healthcheck_interval ' => env ('HEALTH_CHECK_INTERVAL ' , 24 )
4+ 'healthcheck_interval ' => env ('HEALTH_CHECK_INTERVAL ' , 24 ),
5+ 'cleanup_site_delay ' => env ('CLEANUP_SITE_DELAY ' , 7 ),
56];
You can’t perform that action at this time.
0 commit comments