Documentation
¶
Overview ¶
Package schedule provides durable one-shot schedule records.
Index ¶
- Constants
- Variables
- type CreateArgs
- type Schedule
- type Store
- func (s *Store) Cancel(id string) (Schedule, error)
- func (s *Store) Create(record Schedule) (Schedule, error)
- func (s *Store) Get(id string) (Schedule, bool)
- func (s *Store) List() []Schedule
- func (s *Store) Load() error
- func (s *Store) MarkDelivered(id string, deliveredAt time.Time) (Schedule, error)
- func (s *Store) Path() string
- func (s *Store) Save() error
Constants ¶
const ( StatusPending = "pending" StatusCanceled = "canceled" StatusDelivered = "delivered" )
Variables ¶
var ErrNotFound = errors.New("schedule not found")
Functions ¶
This section is empty.
Types ¶
type CreateArgs ¶
CreateArgs is the user-supplied portion of a schedule creation request.
func ParseCreateArgs ¶
func ParseCreateArgs(input string, defaultLocation *time.Location) (CreateArgs, error)
ParseCreateArgs parses either:
at YYYY-MM-DD HH:MM [IANA-zone] -- text in <duration> -- text
Times without an explicit zone use defaultLocation. Returned due times are always UTC. For deterministic relative times, use ParseCreateArgsAt.
func ParseCreateArgsAt ¶
func ParseCreateArgsAt(input string, now time.Time, defaultLocation *time.Location) (CreateArgs, error)
ParseCreateArgsAt is ParseCreateArgs using now as the reference for relative schedules.
type Schedule ¶
type Schedule struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Text string `json:"text"`
DueAt time.Time `json:"due_at"`
TimeZone string `json:"time_zone"`
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
DeliveredAt time.Time `json:"delivered_at,omitempty"`
OccurrenceID string `json:"occurrence_id"`
}
Schedule is a single, durable delivery occurrence. All stored timestamps are normalized to UTC.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps schedules in a caller-selected JSON file. Successful mutating operations are persisted before they return.
func NewStore ¶
NewStore creates an empty store for path. Call Load or Open to restore an existing file.
func (*Store) Cancel ¶
Cancel marks a record canceled and persists it. Canceling an already canceled record succeeds without changing it.
func (*Store) Create ¶
Create persists record and returns its fully populated form. ID, OccurrenceID, CreatedAt, and pending Status are assigned when omitted.
func (*Store) Load ¶
Load replaces the in-memory records with those in the store file. A missing file is treated as an empty store.
func (*Store) MarkDelivered ¶
MarkDelivered records that a schedule's single occurrence was accepted by its delivery target. It is idempotent so recovery code can safely repeat it after a crash between prompt persistence and this store update.