33 lines
865 B
PHP
33 lines
865 B
PHP
<?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
|
|
}
|
|
});
|
|
}
|
|
}
|