Skip to content

Commit 246184d

Browse files
authored
[Feature] System maintenance command to keep things healthy (alexjustesen#1009)
1 parent be306a9 commit 246184d

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Artisan;
7+
8+
class SystemMaintenance extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'app:system-maintenance';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Functions to keep Speedtest Tracker nice and healthy.';
23+
24+
/**
25+
* Execute the console command.
26+
*/
27+
public function handle()
28+
{
29+
$this->refreshCache();
30+
31+
return Command::SUCCESS;
32+
}
33+
34+
/**
35+
* Clear and refresh the cache.
36+
*/
37+
protected function refreshCache(): void
38+
{
39+
Artisan::call('optimize:clear');
40+
41+
Artisan::call('optimize');
42+
}
43+
}

app/Console/Kernel.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Console;
44

55
use App\Console\Commands\RunOoklaSpeedtest;
6+
use App\Console\Commands\SystemMaintenance;
67
use App\Console\Commands\VersionChecker;
78
use App\Settings\GeneralSettings;
89
use Cron\CronExpression;
@@ -18,6 +19,13 @@ protected function schedule(Schedule $schedule): void
1819
{
1920
$settings = new GeneralSettings();
2021

22+
/**
23+
* Perform system maintenance weekly on Sunday morning,
24+
* start off the week nice and fresh.
25+
*/
26+
$schedule->command(SystemMaintenance::class)->weeklyOn(0)
27+
->timezone($settings->timezone ?? 'UTC');
28+
2129
/**
2230
* Checked for new versions weekly on Thursday because
2331
* I usually do releases on Thursday or Friday.

0 commit comments

Comments
 (0)