Files
Agent-System/internal/server/notification_reminder_loop.go
T
weichen f3f23a3018 feat(errcode): 用稳定错误码记录 HTTP 与异步失败
失败响应此前不写日志,request_id 无法对照原因。注册表不覆盖处理器已经给出的 HTTP 状态。
2026-09-28 02:27:16 +00:00

55 lines
1.1 KiB
Go

package server
import (
"context"
"log/slog"
"time"
"chat-agent-system/internal/errcode"
)
const defaultReminderPollInterval = 15 * time.Minute
func (s *Server) startNotificationReminderLoop() {
if s == nil || s.notifySvc() == nil || !s.notifySvc().Available() {
return
}
stopCh, ok := s.reminderLoop.start()
if !ok {
return
}
go func() {
ticker := time.NewTicker(defaultReminderPollInterval)
defer ticker.Stop()
s.runStageAdvanceReminders(context.Background())
for {
select {
case <-stopCh:
return
case <-ticker.C:
s.runStageAdvanceReminders(context.Background())
}
}
}()
}
func (s *Server) runStageAdvanceReminders(ctx context.Context) {
if s.notifySvc() == nil || !s.notifySvc().Available() {
return
}
n, err := s.notifySvc().ProcessStageAdvanceReminders(ctx)
if err != nil {
slog.Warn("stage advance reminder scan failed", "error", err)
errcode.Report(ctx, errcode.Event{
Code: "REMINDER_SCAN_FAILED",
Module: "notification",
Source: "async",
Upstream: err.Error(),
})
return
}
if n > 0 {
slog.Info("stage advance 24h reminders sent", "count", n)
}
}