(ctx context.Context)
| 4349 | } |
| 4350 | |
| 4351 | func (p *Server) acquireLoop(ctx context.Context) { |
| 4352 | acquireTicker := p.clock.NewTicker( |
| 4353 | p.pendingChatAcquireInterval, |
| 4354 | "chatd", |
| 4355 | "acquire", |
| 4356 | ) |
| 4357 | defer acquireTicker.Stop() |
| 4358 | |
| 4359 | staleRecoveryInterval := p.inFlightChatStaleAfter / staleRecoveryIntervalDivisor |
| 4360 | staleTicker := p.clock.NewTicker( |
| 4361 | staleRecoveryInterval, |
| 4362 | "chatd", |
| 4363 | "stale-recovery", |
| 4364 | ) |
| 4365 | defer staleTicker.Stop() |
| 4366 | |
| 4367 | for { |
| 4368 | select { |
| 4369 | case <-ctx.Done(): |
| 4370 | return |
| 4371 | case <-acquireTicker.C: |
| 4372 | p.processOnce(ctx) |
| 4373 | case <-p.wakeCh: |
| 4374 | p.processOnce(ctx) |
| 4375 | case <-staleTicker.C: |
| 4376 | p.recoverStaleChats(ctx) |
| 4377 | if debugSvc := p.existingDebugService(); debugSvc != nil { |
| 4378 | if _, err := debugSvc.FinalizeStale(ctx); err != nil { |
| 4379 | p.logger.Warn(ctx, "failed to finalize stale chat debug rows", slog.Error(err)) |
| 4380 | } |
| 4381 | } |
| 4382 | } |
| 4383 | } |
| 4384 | } |
| 4385 | |
| 4386 | // signalWake wakes the run loop so it calls processOnce immediately. |
| 4387 | // Non-blocking: if a signal is already pending it is a no-op. |
no test coverage detected