fix(storage): clear stale disk usage cache
Forget cached storage threshold state when reported disk usage drops below the alert threshold, allowing future threshold crossings to dispatch a fresh storage check.
This commit is contained in:
parent
43884823c6
commit
097efd14ce
2 changed files with 35 additions and 0 deletions
|
|
@ -143,6 +143,8 @@ public function handle()
|
||||||
&& (string) $lastPercentage !== (string) $filesystemUsageRoot) {
|
&& (string) $lastPercentage !== (string) $filesystemUsageRoot) {
|
||||||
Cache::put($storageCacheKey, $filesystemUsageRoot, 600);
|
Cache::put($storageCacheKey, $filesystemUsageRoot, 600);
|
||||||
ServerStorageCheckJob::dispatch($this->server, $filesystemUsageRoot);
|
ServerStorageCheckJob::dispatch($this->server, $filesystemUsageRoot);
|
||||||
|
} elseif ($filesystemUsageRoot !== null && $filesystemUsageRoot < $diskThreshold) {
|
||||||
|
Cache::forget($storageCacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->containers->isEmpty()) {
|
if ($this->containers->isEmpty()) {
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,39 @@
|
||||||
Queue::assertNotPushed(ServerStorageCheckJob::class);
|
Queue::assertNotPushed(ServerStorageCheckJob::class);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('clears stale storage cache when disk usage drops below threshold', function () {
|
||||||
|
$team = Team::factory()->create();
|
||||||
|
$server = Server::factory()->create(['team_id' => $team->id]);
|
||||||
|
$storageCacheKey = 'storage-check:'.$server->id;
|
||||||
|
|
||||||
|
Cache::put($storageCacheKey, 85, 600);
|
||||||
|
|
||||||
|
$belowThresholdData = [
|
||||||
|
'containers' => [],
|
||||||
|
'filesystem_usage_root' => ['used_percentage' => 45],
|
||||||
|
];
|
||||||
|
|
||||||
|
$job = new PushServerUpdateJob($server, $belowThresholdData);
|
||||||
|
$job->handle();
|
||||||
|
|
||||||
|
Queue::assertNotPushed(ServerStorageCheckJob::class);
|
||||||
|
expect(Cache::missing($storageCacheKey))->toBeTrue();
|
||||||
|
|
||||||
|
Queue::fake();
|
||||||
|
|
||||||
|
$aboveThresholdData = [
|
||||||
|
'containers' => [],
|
||||||
|
'filesystem_usage_root' => ['used_percentage' => 85],
|
||||||
|
];
|
||||||
|
|
||||||
|
$job = new PushServerUpdateJob($server, $aboveThresholdData);
|
||||||
|
$job->handle();
|
||||||
|
|
||||||
|
Queue::assertPushed(ServerStorageCheckJob::class, function ($job) use ($server) {
|
||||||
|
return $job->server->id === $server->id && $job->percentage === 85;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('does not dispatch storage check when disk percentage is unchanged', function () {
|
it('does not dispatch storage check when disk percentage is unchanged', function () {
|
||||||
$team = Team::factory()->create();
|
$team = Team::factory()->create();
|
||||||
$server = Server::factory()->create(['team_id' => $team->id]);
|
$server = Server::factory()->create(['team_id' => $team->id]);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue