schedule

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 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 provides durable one-shot schedule records.

Index

Constants

View Source
const (
	StatusPending   = "pending"
	StatusCanceled  = "canceled"
	StatusDelivered = "delivered"
)

Variables

View Source
var ErrNotFound = errors.New("schedule not found")

Functions

This section is empty.

Types

type CreateArgs

type CreateArgs struct {
	DueAt    time.Time
	TimeZone string
	Text     string
}

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

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) 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.

Jump to

Keyboard shortcuts

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