scheduler_outbox.go 1007 B

12345678910111213141516171819202122232425262728293031
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. )
  6. type SchedulerOutboxEvent struct {
  7. ID int64
  8. EventType string
  9. AccountID *int64
  10. GroupID *int64
  11. Payload map[string]any
  12. CreatedAt time.Time
  13. }
  14. // SchedulerOutboxRepository 提供调度 outbox 的读取接口。
  15. type SchedulerOutboxRepository interface {
  16. ListAfterAndReleaseDedup(ctx context.Context, afterID int64, limit int) ([]SchedulerOutboxEvent, error)
  17. // FirstCreatedAtAfter 返回指定水位之后第一条待消费事件的创建时间,不领取事件或修改去重键。
  18. FirstCreatedAtAfter(ctx context.Context, afterID int64) (time.Time, bool, error)
  19. MaxID(ctx context.Context) (int64, error)
  20. DeleteConsumedUpTo(ctx context.Context, watermark int64, limit int) (int64, error)
  21. TryAcquireCleanupLock(ctx context.Context) (SchedulerOutboxCleanupLease, bool, error)
  22. }
  23. // SchedulerOutboxCleanupLease holds the PostgreSQL advisory lock used by
  24. // scheduler outbox cleanup.
  25. type SchedulerOutboxCleanupLease interface {
  26. Release()
  27. }