You've already forked agentic-coding-workflow
feat(workspace,jobs): emit sync_aborted_on_restart audit + enrich worktree.pruned metadata
- workspace.ResetStuckSyncStatuses now returns affected IDs so app.New can record one workspace.sync_aborted_on_restart audit per reset row - worktree_prune audit metadata gains workspace_id and path alongside existing branch - updated fakeRepo + integration test for new ResetStuckSyncStatuses signature - add TestWorktreePrune_AuditMetadataContainsWorkspaceIDAndPath
This commit is contained in:
@@ -35,12 +35,13 @@ RETURNING *;
|
||||
-- name: DeleteWorkspace :exec
|
||||
DELETE FROM workspaces WHERE id = $1;
|
||||
|
||||
-- name: ResetStuckSyncStatuses :exec
|
||||
-- name: ResetStuckSyncStatuses :many
|
||||
UPDATE workspaces
|
||||
SET sync_status = 'error',
|
||||
last_sync_error = 'process_restarted_during_' || sync_status,
|
||||
updated_at = now()
|
||||
WHERE sync_status IN ('cloning', 'syncing');
|
||||
WHERE sync_status IN ('cloning', 'syncing')
|
||||
RETURNING id, last_sync_error;
|
||||
|
||||
-- name: ListFetchTargets :many
|
||||
SELECT w.id, p.owner_id, w.name, w.main_path
|
||||
|
||||
@@ -44,7 +44,9 @@ type Repository interface {
|
||||
UpdateWorkspaceCore(ctx context.Context, id uuid.UUID, name, description, defaultBranch string) (*Workspace, error)
|
||||
UpdateWorkspaceSyncStatus(ctx context.Context, id uuid.UUID, st SyncStatus, syncedAt *time.Time, errMsg string) (*Workspace, error)
|
||||
DeleteWorkspace(ctx context.Context, id uuid.UUID) error
|
||||
ResetStuckSyncStatuses(ctx context.Context) error
|
||||
// ResetStuckSyncStatuses 把启动时残留的 cloning/syncing 复位为 error,
|
||||
// 返回被复位的工作区 ID 列表(按发生顺序),由调用方写 audit。
|
||||
ResetStuckSyncStatuses(ctx context.Context) ([]uuid.UUID, error)
|
||||
|
||||
// Worktree (no-tx 部分)
|
||||
GetWorktreeByID(ctx context.Context, id uuid.UUID) (*Worktree, error)
|
||||
@@ -240,11 +242,16 @@ func (r *pgRepo) DeleteWorkspace(ctx context.Context, id uuid.UUID) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *pgRepo) ResetStuckSyncStatuses(ctx context.Context) error {
|
||||
if err := r.q.ResetStuckSyncStatuses(ctx); err != nil {
|
||||
return errs.Wrap(err, errs.CodeInternal, "reset stuck sync")
|
||||
func (r *pgRepo) ResetStuckSyncStatuses(ctx context.Context) ([]uuid.UUID, error) {
|
||||
rows, err := r.q.ResetStuckSyncStatuses(ctx)
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "reset stuck sync")
|
||||
}
|
||||
return nil
|
||||
ids := make([]uuid.UUID, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
ids = append(ids, fromPgUUID(row.ID))
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// ===== Workspace fetch (jobs runner) =====
|
||||
|
||||
@@ -241,17 +241,38 @@ func (q *Queries) MarkSyncingCAS(ctx context.Context, id pgtype.UUID) (int64, er
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const resetStuckSyncStatuses = `-- name: ResetStuckSyncStatuses :exec
|
||||
const resetStuckSyncStatuses = `-- name: ResetStuckSyncStatuses :many
|
||||
UPDATE workspaces
|
||||
SET sync_status = 'error',
|
||||
last_sync_error = 'process_restarted_during_' || sync_status,
|
||||
updated_at = now()
|
||||
WHERE sync_status IN ('cloning', 'syncing')
|
||||
RETURNING id, last_sync_error
|
||||
`
|
||||
|
||||
func (q *Queries) ResetStuckSyncStatuses(ctx context.Context) error {
|
||||
_, err := q.db.Exec(ctx, resetStuckSyncStatuses)
|
||||
return err
|
||||
type ResetStuckSyncStatusesRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
LastSyncError *string `json:"last_sync_error"`
|
||||
}
|
||||
|
||||
func (q *Queries) ResetStuckSyncStatuses(ctx context.Context) ([]ResetStuckSyncStatusesRow, error) {
|
||||
rows, err := q.db.Query(ctx, resetStuckSyncStatuses)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ResetStuckSyncStatusesRow
|
||||
for rows.Next() {
|
||||
var i ResetStuckSyncStatusesRow
|
||||
if err := rows.Scan(&i.ID, &i.LastSyncError); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateWorkspaceCore = `-- name: UpdateWorkspaceCore :one
|
||||
|
||||
@@ -75,7 +75,9 @@ func (f *fakeRepo) DeleteWorkspace(_ context.Context, id uuid.UUID) error {
|
||||
delete(f.wss, id)
|
||||
return nil
|
||||
}
|
||||
func (f *fakeRepo) ResetStuckSyncStatuses(_ context.Context) error { return nil }
|
||||
func (f *fakeRepo) ResetStuckSyncStatuses(_ context.Context) ([]uuid.UUID, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (f *fakeRepo) ListFetchTargets(_ context.Context) ([]FetchTarget, error) { return nil, nil }
|
||||
func (f *fakeRepo) MarkSyncing(_ context.Context, _ uuid.UUID) (bool, error) { return false, nil }
|
||||
func (f *fakeRepo) MarkFetchResult(_ context.Context, _ uuid.UUID, _ bool, _ string) error {
|
||||
|
||||
Reference in New Issue
Block a user