mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +08:00
chore(coderd/x/chatd/chatdebug): clean up after the chatd refactor (#26345)
Addresses https://github.com/coder/coder/pull/26109#discussion_r3379164243 and https://github.com/coder/coder/pull/26109#discussion_r3379151284
This commit is contained in:
@@ -524,7 +524,9 @@ func (s *Service) TouchStep(
|
||||
|
||||
// TouchRun bumps the run's updated_at timestamp without changing any
|
||||
// other fields. Runner-owned debug turns use this while no model step is
|
||||
// active, such as requires-action waits.
|
||||
// active, such as requires-action waits. It is a no-op when the service
|
||||
// is nil or either ID is uuid.Nil, since debug tracking is optional and
|
||||
// callers may not have an open run.
|
||||
func (s *Service) TouchRun(ctx context.Context, runID uuid.UUID, chatID uuid.UUID) error {
|
||||
if s == nil || runID == uuid.Nil || chatID == uuid.Nil {
|
||||
return nil
|
||||
@@ -538,7 +540,9 @@ func (s *Service) TouchRun(ctx context.Context, runID uuid.UUID, chatID uuid.UUI
|
||||
}
|
||||
|
||||
// LaunchRunHeartbeat starts a goroutine that periodically touches an
|
||||
// open run until done is closed or ctx is canceled.
|
||||
// open run until done is closed or ctx is canceled. It is a no-op when
|
||||
// the service is nil, either ID is uuid.Nil, or done is nil, since debug
|
||||
// tracking is optional and callers may not have an open run.
|
||||
func (s *Service) LaunchRunHeartbeat(ctx context.Context, runID uuid.UUID, chatID uuid.UUID, done <-chan struct{}) {
|
||||
if s == nil || runID == uuid.Nil || chatID == uuid.Nil || done == nil {
|
||||
return
|
||||
@@ -548,7 +552,7 @@ func (s *Service) LaunchRunHeartbeat(ctx context.Context, runID uuid.UUID, chatI
|
||||
interval := s.heartbeatInterval()
|
||||
ticker := s.clock.NewTicker(interval, "chatdebug", "run-heartbeat")
|
||||
defer ticker.Stop()
|
||||
resetTicker := func() {
|
||||
maybeResetTicker := func() {
|
||||
if newInterval := s.heartbeatInterval(); newInterval != interval {
|
||||
interval = newInterval
|
||||
ticker.Reset(interval, "chatdebug", "run-heartbeat")
|
||||
@@ -562,7 +566,7 @@ func (s *Service) LaunchRunHeartbeat(ctx context.Context, runID uuid.UUID, chatI
|
||||
return
|
||||
case <-thresholdCh:
|
||||
thresholdCh = s.thresholdChan()
|
||||
resetTicker()
|
||||
maybeResetTicker()
|
||||
case <-ticker.C:
|
||||
if err := s.TouchRun(ctx, runID, chatID); err != nil {
|
||||
s.log.Debug(ctx, "run heartbeat touch failed",
|
||||
@@ -570,7 +574,7 @@ func (s *Service) LaunchRunHeartbeat(ctx context.Context, runID uuid.UUID, chatI
|
||||
slog.F("run_id", runID),
|
||||
)
|
||||
}
|
||||
resetTicker()
|
||||
maybeResetTicker()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user