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

Đang mở
#466 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@fx-kurumi đang làm issue này rồi.

Từ ngày 13/11/2026.

  • #467 của @fx-kurumi — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
30/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

现状问题

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)保持通过
Ngôn ngữ chính
Go
Star
141
Fork
28
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
113

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Tencent/LoopForge

Tất cả issue của Tencent/LoopForge

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.