添加 ServerRateLimitsSyncService.php
This commit is contained in:
parent
a4e5fbd3d2
commit
4b8d511a98
32
ServerRateLimitsSyncService.php
Normal file
32
ServerRateLimitsSyncService.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Nodes;
|
||||
|
||||
use App\Exceptions\Repository\Proxmox\ProxmoxConnectionException;
|
||||
use App\Models\Node;
|
||||
use App\Models\Server;
|
||||
use App\Services\Servers\ServerNetworkService;
|
||||
|
||||
class ServerRateLimitsSyncService
|
||||
{
|
||||
public function __construct(private ServerNetworkService $service)
|
||||
{
|
||||
}
|
||||
|
||||
public function handle(Node $node): void
|
||||
{
|
||||
$servers = $node->servers;
|
||||
|
||||
$servers->each(function (Server $server) {
|
||||
try {
|
||||
if ($server->bandwidth_usage >= $server->bandwidth_limit && isset($server->bandwidth_limit)) {
|
||||
$this->service->setRateLimit($server, 1);
|
||||
} else {
|
||||
$this->service->setRateLimit($server);
|
||||
}
|
||||
} catch (ProxmoxConnectionException $e) {
|
||||
// do nothing
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user