2026-04-27 02:29:42 +08:00

31 lines
932 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import "context"
// ProcessPendingOutbox 把待投递事件补偿性地推送给异步消费者。
func (s *Service) ProcessPendingOutbox(ctx context.Context, limit int) error {
// 补偿 worker 从 repository 扫描 pending 事件;同步 room->im 失败不会回滚房间状态。
records, err := s.repository.ListPendingOutbox(ctx, limit)
if err != nil {
return err
}
for _, record := range records {
if err := s.outboxPublisher.PublishOutboxEvent(ctx, record.Envelope); err != nil {
// 投递失败保持 pending并记录错误和重试次数等待下一轮 worker 再试。
if markErr := s.repository.MarkOutboxFailed(ctx, record.EventID, err.Error()); markErr != nil {
return markErr
}
continue
}
// 只有外部发布成功后才能标记 published。
if err := s.repository.MarkOutboxPublished(ctx, record.EventID); err != nil {
return err
}
}
return nil
}