schedule

package
v0.48.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	StatusPending   = "pending"
	StatusCanceled  = "canceled"
	StatusDelivered = "delivered"
)
View Source
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

View Source
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

func NewStore(path string) *Store

NewStore creates an empty store for path. Call Load or Open to restore an existing file.

func Open

func Open(path string) (*Store, error)

Open loads the store at path. A missing file is an empty store.

func (*Store) Cancel

func (s *Store) Cancel(id string) (Schedule, error)

Cancel marks a record canceled and persists it. Canceling an already canceled record succeeds without changing it.

func (*Store) Create

func (s *Store) Create(record Schedule) (Schedule, error)

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

func (s *Store) DeleteSession(sessionID string) error

DeleteSession removes every record of a session, whatever its status: once the session is gone nothing can be delivered to it.

func (*Store) Get

func (s *Store) Get(id string) (Schedule, bool)

Get returns a record by ID.

func (*Store) List

func (s *Store) List() []Schedule

List returns all records ordered by due time and then ID.

func (*Store) Load

func (s *Store) Load() error

Load replaces the in-memory records with those in the store file. A missing file is treated as an empty store.

func (*Store) MarkDelivered

func (s *Store) MarkDelivered(id string, deliveredAt time.Time) (Schedule, error)

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.

func (*Store) Path

func (s *Store) Path() string

Path returns the file the store persists to.

func (*Store) PurgeSettled added in v0.45.0

func (s *Store) PurgeSettled(cutoff time.Time) (int, error)

PurgeSettled removes delivered and canceled records due before cutoff and returns how many it dropped.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL