occurrence

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package occurrence computes the LOGICAL fire times of a recurring schedule.

The distinction this package exists to defend: an occurrence is a property of the schedule and the calendar, not of when a daemon happened to wake up. A weekly task due Monday 10:00 has exactly one Monday-10:00 occurrence whether the machine was awake for it, noticed it eight hours late, or was restarted three times in between. That is what lets a duplicate scheduler callback, a restart, and a late catch-up all resolve to the SAME ledger identity, so the unique (task, occurrence) constraint can do its job.

It lives under internal/gateway because that is where cron parsing is allowed to live (internal/guard.TestSingleCronParser): one scheduler, one parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Between

func Between(s Spec, after, until time.Time, limit int) (times []time.Time, dropped int, err error)

Between returns the logical occurrences in the half-open window (after, until], oldest first, at most limit of them.

When there are more than limit, the MOST RECENT are kept and the count of dropped older ones is returned. Recency is the right bias: a stale hourly occurrence from three weeks ago has almost no value, and replaying thousands of them is how a laptop returning from a long sleep turns into a stampede.

func ID

func ID(s Spec, at time.Time) string

ID is the durable identity of ONE logical firing. This is the string that becomes the ledger's occurrence key, so it must depend only on the schedule and the calendar — never on wall-clock-at-discovery, hostname, or attempt.

func Next

func Next(s Spec, t time.Time) (time.Time, bool, error)

Next returns the next logical occurrence strictly after t, for display.

func Prev

func Prev(s Spec, t time.Time, lookback time.Duration) (time.Time, bool, error)

Prev returns the most recent logical occurrence at or before t. Used to place a NEWLY SEEN trigger in its series: without it a brand-new weekly task would look like it had missed every Monday since the epoch.

Types

type Spec

type Spec struct {
	Cron  string
	Every string
	At    string
	TZ    string // named zone for Cron; empty = local
}

Spec is a trigger's timing, in the same three forms the rest of memcode uses. Exactly one of Cron, Every or At is set.

func (Spec) Key

func (s Spec) Key() string

Key identifies the SCHEDULE (not one firing of it), so per-trigger state can be stored and a cadence edit starts a fresh series rather than inheriting the old one's position.

func (Spec) Kind

func (s Spec) Kind() string

Kind names the spec's form, for identities and error messages.

Jump to

Keyboard shortcuts

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