git 逻辑

This commit is contained in:
2026-06-10 15:30:52 +08:00
parent 41f2a84979
commit 023ab2f30e
17 changed files with 221 additions and 64 deletions
+5 -3
View File
@@ -82,13 +82,15 @@ func (r *WorkspaceFetch) fetchOne(ctx context.Context, t WorkspaceFetchTarget) {
// 别的 runner / 手工同步抢先了
return
}
// 即便 runner ctx 因关停被取消,fetch 结果状态仍需可靠落库,避免行永久残留 syncing。
writeCtx := context.WithoutCancel(ctx)
if fetchErr := r.gitr.Fetch(ctx, t.MainPath, t.ID); fetchErr != nil {
msg := truncate(fetchErr.Error(), 2000)
if err := r.repo.MarkFetchResult(ctx, t.ID, false, msg); err != nil {
if err := r.repo.MarkFetchResult(writeCtx, t.ID, false, msg); err != nil {
r.log.Error("workspace_fetch.mark_fail", "workspace_id", t.ID, "err", err.Error())
return
}
if derr := r.disp.Dispatch(ctx, notify.Message{
if derr := r.disp.Dispatch(writeCtx, notify.Message{
UserID: t.OwnerID,
Topic: "workspace.sync_failed",
Severity: notify.SeverityError,
@@ -106,7 +108,7 @@ func (r *WorkspaceFetch) fetchOne(ctx context.Context, t WorkspaceFetchTarget) {
r.log.Warn("workspace_fetch.failed", "workspace_id", t.ID, "err", msg)
return
}
if err := r.repo.MarkFetchResult(ctx, t.ID, true, ""); err != nil {
if err := r.repo.MarkFetchResult(writeCtx, t.ID, true, ""); err != nil {
r.log.Error("workspace_fetch.mark_ok", "workspace_id", t.ID, "err", err.Error())
}
}