Refactor ServerStorageCheckJob handle method to improve error handling and messaging

This commit is contained in:
Andras Bacsai
2024-10-24 15:08:22 +02:00
parent d938a6ce8f
commit d55b444bb8

View File

@@ -31,8 +31,6 @@ class ServerStorageCheckJob implements ShouldBeEncrypted, ShouldQueue
{
try {
if (! $this->server->isFunctional()) {
ray('Server is not ready.');
return 'Server is not ready.';
}
$team = data_get($this->server, 'team');
@@ -42,7 +40,7 @@ class ServerStorageCheckJob implements ShouldBeEncrypted, ShouldQueue
$this->percentage = $this->server->storageCheck();
}
if (! $this->percentage) {
throw new \Exception('No percentage could be retrieved.');
return 'No percentage could be retrieved.';
}
if ($this->percentage > $serverDiskUsageNotificationThreshold) {
$executed = RateLimiter::attempt(
@@ -55,7 +53,7 @@ class ServerStorageCheckJob implements ShouldBeEncrypted, ShouldQueue
);
if (! $executed) {
throw new \Exception('Too many messages sent!');
return 'Too many messages sent!';
}
} else {
RateLimiter::hit('high-disk-usage:'.$this->server->id, 600);