FinalizeStale finalizes stale in-flight debug rows and emits a broadcast.
( ctx context.Context, )
| 576 | |
| 577 | // FinalizeStale finalizes stale in-flight debug rows and emits a broadcast. |
| 578 | func (s *Service) FinalizeStale( |
| 579 | ctx context.Context, |
| 580 | ) (database.FinalizeStaleChatDebugRowsRow, error) { |
| 581 | now := s.clock.Now() |
| 582 | result, err := s.db.FinalizeStaleChatDebugRows( |
| 583 | chatdContext(ctx), |
| 584 | database.FinalizeStaleChatDebugRowsParams{ |
| 585 | Now: now, |
| 586 | UpdatedBefore: now.Add(-s.staleThreshold()), |
| 587 | }, |
| 588 | ) |
| 589 | if err != nil { |
| 590 | return database.FinalizeStaleChatDebugRowsRow{}, err |
| 591 | } |
| 592 | |
| 593 | if result.RunsFinalized > 0 || result.StepsFinalized > 0 { |
| 594 | s.publishEvent(ctx, uuid.Nil, EventKindFinalize, uuid.Nil, uuid.Nil) |
| 595 | } |
| 596 | return result, nil |
| 597 | } |
| 598 | |
| 599 | // FinalizeRunParams bundles the arguments for FinalizeRun. |
| 600 | type FinalizeRunParams struct { |