feat: add notifier scheduler and NotifyOnce sent-tracking

This commit is contained in:
2026-07-19 22:32:57 +03:00
parent 3af33bd728
commit 11f838ace9
6 changed files with 401 additions and 4 deletions

View File

@@ -0,0 +1,31 @@
package notifier
import (
"fmt"
"time"
"github.com/robfig/cron/v3"
)
// CronSchedule wraps a robfig/cron schedule to satisfy the notifier.Schedule
// interface used by StartScheduler. The spec follows the standard 5-field cron
// syntax (e.g. "0 9 * * *" for daily at 09:00 in the process local time).
type CronSchedule struct {
spec string
c cron.Schedule
}
// NewCronSchedule parses a cron spec and returns a Schedule. An error is
// returned if the spec is not a valid cron expression.
func NewCronSchedule(spec string) (*CronSchedule, error) {
c, err := cron.ParseStandard(spec)
if err != nil {
return nil, fmt.Errorf("parse cron schedule %q: %w", spec, err)
}
return &CronSchedule{spec: spec, c: c}, nil
}
// Next returns the next time the schedule fires after t.
func (s *CronSchedule) Next(t time.Time) time.Time {
return s.c.Next(t)
}