Files
Agent-System/internal/app/runtime_ports.go
T
WeiCHEN 9071c272bf refactor(server): drop Server pool; route health/heal/vault via Runtime
Remove production *pgxpool.Pool from Server, centralize domain→HTTP
status mapping, and expose Runtime ports for task-store readiness,
duty heal, and artifact vault registry. Allow app→docduty for heal wiring.
2026-09-22 21:44:56 +08:00

42 lines
1.3 KiB
Go

package app
import (
"context"
"log"
"chat-agent-system/internal/artifactvault"
"chat-agent-system/internal/docduty"
"chat-agent-system/internal/taskrun"
)
// TaskStoreReady reports whether task_runs tables are available.
// HTTP adapters must use this instead of holding *pgxpool.Pool.
func (r *Runtime) TaskStoreReady(ctx context.Context) bool {
if r == nil || r.Pool == nil {
return false
}
return taskrun.TablesReady(ctx, r.Pool)
}
// HealProjectDuties syncs controlled-document duties after project membership changes.
func (r *Runtime) HealProjectDuties(ctx context.Context, projectID int64) error {
if r == nil || r.Pool == nil || projectID <= 0 {
return nil
}
_, _, err := docduty.HealProjectDocuments(ctx, r.Pool, projectID)
if err != nil {
log.Printf("[docduty] heal project %d after member change failed: %v", projectID, err)
}
return err
}
// ArtifactVaultRegistry returns a PG-backed registry when the pool is available,
// otherwise an in-memory stub suitable for FAV publisher off / tests.
// HTTP adapters must not hold *pgxpool.Pool to construct the registry.
func (r *Runtime) ArtifactVaultRegistry() artifactvault.Registry {
if r == nil || r.Pool == nil {
return artifactvault.NewMemoryRegistry()
}
return artifactvault.NewPGRegistry(r.Pool)
}