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

Abierto
#466 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@fx-kurumi ya está trabajando en esto.

Desde el 13/11/2026.

  • #467 de @fx-kurumi — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
Medio día
Aptitud para principiantes
30/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

现状问题

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)保持通过
Lenguaje dominante
Go
Estrellas
141
Forks
28
Merge medio
1 d 15 h
PR fusionados (30 d)
113

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Tencent/LoopForge

Todos los issues de Tencent/LoopForge

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.