feat(api): 新增节点流量悬浮详情与即时自动上线同步
为 server/manage/getNodes 返回节点级今日、本月与累计流量统计, 并在节点管理页名称悬浮层展示上行、下行和合计流量。 同时为自动上线补齐单节点同步入口,在管理端保存、 批量更新以及 REST/WS 心跳后立即同步 show 状态, 避免复制节点后开启自动上线仍需等待定时任务。 另优化管理端前端 Docker 发布流程,默认仅构建 amd64, 并收敛 BuildKit 缓存导出以缩短发布时间
This commit is contained in:
@@ -6,7 +6,9 @@ use App\Models\Server;
|
||||
use App\Models\ServerGfwCheck;
|
||||
use App\Services\ServerAutoOnlineService;
|
||||
use App\Services\ServerService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ServerAutoOnlineServiceTest extends TestCase
|
||||
@@ -31,7 +33,7 @@ class ServerAutoOnlineServiceTest extends TestCase
|
||||
'auto_online' => false,
|
||||
]);
|
||||
|
||||
ServerService::touchNode($managedOnline);
|
||||
$this->markNodeOnline($managedOnline);
|
||||
|
||||
$result = app(ServerAutoOnlineService::class)->sync();
|
||||
|
||||
@@ -54,7 +56,7 @@ class ServerAutoOnlineServiceTest extends TestCase
|
||||
'gfw_check_enabled' => true,
|
||||
]);
|
||||
|
||||
ServerService::touchNode($managedOnline);
|
||||
$this->markNodeOnline($managedOnline);
|
||||
ServerGfwCheck::create([
|
||||
'server_id' => $managedOnline->id,
|
||||
'status' => ServerGfwCheck::STATUS_BLOCKED,
|
||||
@@ -80,7 +82,7 @@ class ServerAutoOnlineServiceTest extends TestCase
|
||||
'gfw_check_enabled' => false,
|
||||
]);
|
||||
|
||||
ServerService::touchNode($managedOnline);
|
||||
$this->markNodeOnline($managedOnline);
|
||||
ServerGfwCheck::create([
|
||||
'server_id' => $managedOnline->id,
|
||||
'status' => ServerGfwCheck::STATUS_BLOCKED,
|
||||
@@ -95,6 +97,37 @@ class ServerAutoOnlineServiceTest extends TestCase
|
||||
$this->assertTrue($managedOnline->fresh()->show);
|
||||
}
|
||||
|
||||
public function test_sync_server_updates_single_auto_online_node(): void
|
||||
{
|
||||
$managedOnline = $this->makeServer([
|
||||
'name' => 'single-managed-online',
|
||||
'show' => false,
|
||||
'auto_online' => true,
|
||||
]);
|
||||
|
||||
$this->markNodeOnline($managedOnline);
|
||||
|
||||
$result = app(ServerAutoOnlineService::class)->syncServer($managedOnline);
|
||||
|
||||
$this->assertSame(1, $result['total']);
|
||||
$this->assertSame(1, $result['updated']);
|
||||
$this->assertSame(1, $result['shown']);
|
||||
$this->assertTrue($managedOnline->fresh()->show);
|
||||
}
|
||||
|
||||
public function test_touch_node_syncs_auto_online_node_immediately(): void
|
||||
{
|
||||
$managedOnline = $this->makeServer([
|
||||
'name' => 'heartbeat-managed-online',
|
||||
'show' => false,
|
||||
'auto_online' => true,
|
||||
]);
|
||||
|
||||
ServerService::touchNode($managedOnline);
|
||||
|
||||
$this->assertTrue($managedOnline->fresh()->show);
|
||||
}
|
||||
|
||||
private function makeServer(array $attributes = []): Server
|
||||
{
|
||||
return Server::create(array_merge([
|
||||
@@ -112,4 +145,13 @@ class ServerAutoOnlineServiceTest extends TestCase
|
||||
'enabled' => true,
|
||||
], $attributes));
|
||||
}
|
||||
|
||||
private function markNodeOnline(Server $server): void
|
||||
{
|
||||
Cache::put(
|
||||
CacheKey::get('SERVER_' . strtoupper($server->type) . '_LAST_CHECK_AT', $server->id),
|
||||
time(),
|
||||
3600
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user