You've already forked agentic-coding-workflow
启动项目逻辑
This commit is contained in:
+36
-1
@@ -46,6 +46,7 @@ import (
|
||||
"github.com/yan1h/agent-coding-workflow/internal/jobs/runners"
|
||||
mcp "github.com/yan1h/agent-coding-workflow/internal/mcp"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/project"
|
||||
runmod "github.com/yan1h/agent-coding-workflow/internal/run"
|
||||
httpx "github.com/yan1h/agent-coding-workflow/internal/transport/http"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/transport/http/middleware"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/user"
|
||||
@@ -61,7 +62,8 @@ type App struct {
|
||||
dispatcher *notify.Dispatcher
|
||||
jobs *jobs.Module
|
||||
jobsCancel context.CancelFunc
|
||||
acpSup *acp.Supervisor // ACP supervisor — ShutdownAll on Run shutdown
|
||||
acpSup *acp.Supervisor // ACP supervisor — ShutdownAll on Run shutdown
|
||||
runSup *runmod.RunSupervisor // run profiles supervisor — ShutdownAll on Run shutdown
|
||||
}
|
||||
|
||||
// New 把所有模块按启动顺序拼装好。任何阶段失败都会返回错误,不留半成品资源。
|
||||
@@ -396,6 +398,31 @@ func New(ctx context.Context, cfg *config.Config, dist embed.FS) (*App, error) {
|
||||
SendBuffer: cfg.Acp.WSSendBuffer,
|
||||
}).Mount(r)
|
||||
|
||||
// ===== run profiles module wiring =====
|
||||
// 进程托管:每个 workspace 的 run profile 作为长驻进程在 main_path 拉起。
|
||||
// 复用 workspace.ProjectAccess(pa) 做 owner+admin 写鉴权。WS 心跳沿用 acp 的
|
||||
// 全局默认值(同类参数,避免新增配置面)。
|
||||
runRepo := runmod.NewPostgresRepository(pool)
|
||||
runSup := runmod.NewSupervisor(runRepo, runmod.SupervisorConfig{
|
||||
KillGrace: cfg.Run.KillGrace,
|
||||
OutBufferLines: cfg.Run.OutBufferLines,
|
||||
OutTailBytes: cfg.Run.OutTailBytes,
|
||||
WSSendBuffer: cfg.Run.WSSendBuffer,
|
||||
ShutdownGrace: cfg.Run.ShutdownGrace,
|
||||
}, log)
|
||||
runSvc := runmod.NewService(runRepo, wsRepo, runSup, pa, auditRec, enc, runmod.ServiceConfig{
|
||||
EnvWhitelist: cfg.Run.EnvWhitelist,
|
||||
KillGrace: cfg.Run.KillGrace,
|
||||
OutTailBytes: cfg.Run.OutTailBytes,
|
||||
}, log)
|
||||
if cfg.Run.Enabled {
|
||||
runmod.NewHandler(runSvc, userSvc, userAdminAdapter{svc: userSvc}, runmod.WSConfig{
|
||||
PingInterval: cfg.Acp.WSPingInterval,
|
||||
PongTimeout: cfg.Acp.WSPongTimeout,
|
||||
SendBuffer: cfg.Run.WSSendBuffer,
|
||||
}).Mount(r)
|
||||
}
|
||||
|
||||
// ===== jobs module wiring =====
|
||||
jobsRepo := jobs.NewPostgresRepository(pool)
|
||||
|
||||
@@ -577,6 +604,7 @@ func New(ctx context.Context, cfg *config.Config, dist embed.FS) (*App, error) {
|
||||
jobs: jobsModule,
|
||||
jobsCancel: jobsCancel,
|
||||
acpSup: acpSup,
|
||||
runSup: runSup,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -606,6 +634,10 @@ func (a *App) Run(ctx context.Context) error {
|
||||
if a.acpSup != nil {
|
||||
a.acpSup.ShutdownAll(shutCtx)
|
||||
}
|
||||
// Stop run-profile subprocesses (整树 kill) on shutdown.
|
||||
if a.runSup != nil {
|
||||
a.runSup.ShutdownAll(shutCtx)
|
||||
}
|
||||
// Stop jobs module first so no in-flight worker can dispatch new
|
||||
// notifications after we begin to drain the dispatcher.
|
||||
if a.jobs != nil && a.cfg.Jobs.Enabled {
|
||||
@@ -631,6 +663,9 @@ func (a *App) Run(ctx context.Context) error {
|
||||
if a.acpSup != nil {
|
||||
a.acpSup.ShutdownAll(drainCtx)
|
||||
}
|
||||
if a.runSup != nil {
|
||||
a.runSup.ShutdownAll(drainCtx)
|
||||
}
|
||||
if a.jobs != nil && a.cfg.Jobs.Enabled {
|
||||
a.jobsCancel()
|
||||
stopCtx, stopCancel := context.WithTimeout(context.Background(), a.cfg.Jobs.ShutdownGrace+5*time.Second)
|
||||
|
||||
Reference in New Issue
Block a user