Let reviews be stopped, and fail stuck reviewers automatically
This commit is contained in:
@@ -525,6 +525,51 @@ func (m *Manager) cancelReviews(ctx context.Context, task api.Task, project api.
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) StopReview(ctx context.Context, reviewID, reason string) (api.Review, error) {
|
||||
m.reviewMu.Lock()
|
||||
defer m.reviewMu.Unlock()
|
||||
r, err := m.store.GetReview(ctx, reviewID)
|
||||
if err != nil {
|
||||
return api.Review{}, err
|
||||
}
|
||||
if r.State != api.ReviewStateRunning {
|
||||
return api.Review{}, fmt.Errorf("%w: review %s is %s, not running", ErrConflict, r.Id, r.State)
|
||||
}
|
||||
task, err := m.store.GetTask(ctx, r.TaskId)
|
||||
if err != nil {
|
||||
return api.Review{}, err
|
||||
}
|
||||
project, err := m.store.GetProject(ctx, task.ProjectId)
|
||||
if err != nil {
|
||||
return api.Review{}, err
|
||||
}
|
||||
m.endReviewer(ctx, r.AgentSessionId, project, r.Id)
|
||||
m.failReview(ctx, r.Id, reason)
|
||||
return m.store.GetReview(ctx, r.Id)
|
||||
}
|
||||
|
||||
func (m *Manager) stopStuckReviewers(ctx context.Context, h Health) {
|
||||
for _, p := range h.Processes {
|
||||
if p.Health != api.HealthStuck {
|
||||
continue
|
||||
}
|
||||
m.mu.Lock()
|
||||
l := m.live[p.SessionId]
|
||||
reviewID := ""
|
||||
if l != nil {
|
||||
reviewID = l.reviewID
|
||||
}
|
||||
m.mu.Unlock()
|
||||
if reviewID == "" {
|
||||
continue
|
||||
}
|
||||
_, err := m.StopReview(ctx, reviewID, fmt.Sprintf("the reviewer went %d minutes without an event", int(StuckAfter/time.Minute)))
|
||||
if err != nil && !errors.Is(err, ErrConflict) {
|
||||
slog.Error("stop stuck reviewer", "review", reviewID, "session", p.SessionId, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) recoverReviews(ctx context.Context) error {
|
||||
err := m.store.ClearReviewRequests(ctx)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user