添加 ServerRateLimitsSyncService.php

This commit is contained in:
ste87 2026-03-13 16:07:26 +08:00
parent a4e5fbd3d2
commit 4b8d511a98

View 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
}
});
}
}