【架构优化】合并 engine/cloud_pool.go 中重复的执行池候选 runner 收集与启用判断

未关闭
#466 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@fx-kurumi 已经在做这个了。

开始于 2026年11月13日。

  • #467 来自 @fx-kurumi —— 未关闭

评估

难度
3/5
预计耗时
半天
新手友好度
30/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
backend

调研方向

The duplicated runner-listing loop sits in pickPoolRunner and CloudPoolStatus, and the duplicated enablement check sits in cloudPoolRunner and cloudPoolRequired, all in internal/engine/cloud_pool.go. Read poolRunnerEligible and cloudPoolServes first, then extract eligiblePoolRunners and the unexported serves method. Pull request #467 already targets this change, so check its state before starting. Done when both call sites share the helpers, go test ./internal/engine/ passes including TestCloudPoolSelectionStatusAndBindingErrors, and the new table-driven tests in cloud_pool_helpers_test.go pass.

由索引模型根据 Issue 内容生成。

描述

现状问题

internal/engine/cloud_pool.go 中有两处重复:

  1. 「列出当前可承接云端执行池任务的 runner」的循环(遍历 e.repo.Runners() 并用 poolRunnerEligible 过滤)在 pickPoolRunner 和 CloudPoolStatus 各写了一遍,一个收集候选、一个计数。
  2. 「执行池已启用且覆盖该项目」的判断 pool.Label != "" && cloudPoolServes(pool.Projects, projectID) 在 cloudPoolRunner 与 cloudPoolRequired 中各写了一遍。

以后调整资格规则或启用条件时容易只改一处。

重构方案

  • 新增 (*Engine).eligiblePoolRunners(label) []domain.Runner,pickPoolRunner 从中随机挑选,CloudPoolStatus 返回其长度。
  • 新增 (CloudRunnerPool).serves(projectID) bool(未导出),cloudPoolRunner / cloudPoolRequired 改为调用它。
  • 函数签名、导出 API、错误文案、选择逻辑均不变。

影响范围

仅 internal/engine/cloud_pool.go,新增测试文件 internal/engine/cloud_pool_helpers_test.go。不涉及对外接口与行为。

验证方式

  • gofmt / go vet ./internal/engine/
  • 新增表驱动测试覆盖 serves 的各种组合,以及 eligiblePoolRunners 对标签/归属/在线状态/版本的过滤,并核对与 CloudPoolStatus、pickPoolRunner 结果一致
  • go test ./internal/engine/ 原有用例(含 TestCloudPoolSelectionStatusAndBindingErrors)保持通过
主要语言
Go
星标
141
派生
28
平均合并
1 天 15 小时
30 天内合并 PR
113

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Tencent/LoopForge 的其他 Issue

查看 Tencent/LoopForge 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。