Documentation
¶
Overview ¶
Package schedule decodes the retired /schedule store (schedules.json), which serve imports once into the task database. It is kept only for that import.
Index ¶
- Constants
- Variables
- type Schedule
- type Store
- func (s *Store) Cancel(id string) (Schedule, error)
- func (s *Store) Create(record Schedule) (Schedule, error)
- func (s *Store) DeleteSession(sessionID string) 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) PurgeSettled(cutoff time.Time) (int, error)
Constants ¶
const ( StatusPending = "pending" StatusCanceled = "canceled" StatusDelivered = "delivered" )
const RetainSettled = 30 * 24 * time.Hour
RetainSettled is how long delivered and canceled records are kept (counted from their due time) before PurgeSettled may drop them. Pending records are never purged by age.
Variables ¶
var ( ErrNotFound = errors.New("schedule not found") // ErrAlreadyDelivered rejects canceling an occurrence that already ran: // relabeling it would rewrite history. ErrAlreadyDelivered = errors.New("schedule was already delivered and cannot be canceled") )
Functions ¶
This section is empty.
Types ¶
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) DeleteSession ¶ added in v0.45.0
DeleteSession removes every record of a session, whatever its status: once the session is gone nothing can be delivered to it.
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.