schema

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSchema    = "heartbeat"
	DefaultLLMSchema = llmschema.DefaultSchema
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Heartbeat

type Heartbeat struct {
	ID string `json:"id"`
	HeartbeatMeta
	Fired     bool       `json:"fired,omitempty"`
	LastFired *time.Time `json:"last_fired,omitempty"`
	Created   time.Time  `json:"created"`
	Modified  *time.Time `json:"modified,omitempty"`
}

func (*Heartbeat) Scan

func (h *Heartbeat) Scan(row pg.Row) error

type HeartbeatIDSelector

type HeartbeatIDSelector string

HeartbeatIDSelector selects a single heartbeat by ID for get/update/delete operations.

func (HeartbeatIDSelector) Select

func (id HeartbeatIDSelector) Select(bind *pg.Bind, op pg.Op) (string, error)

type HeartbeatInsert

type HeartbeatInsert struct {
	Session uuid.UUID `json:"session"`
	HeartbeatMeta
}

HeartbeatInsert contains the fields required to create a new heartbeat row.

func (HeartbeatInsert) Insert

func (h HeartbeatInsert) Insert(bind *pg.Bind) (string, error)

type HeartbeatList

type HeartbeatList struct {
	HeartbeatListRequest
	Count uint         `json:"count"`
	Body  []*Heartbeat `json:"body,omitempty"`
}

HeartbeatList is a pg.Reader that accumulates scanned heartbeat rows.

func (*HeartbeatList) Scan

func (h *HeartbeatList) Scan(row pg.Row) error

func (*HeartbeatList) ScanCount

func (h *HeartbeatList) ScanCount(row pg.Row) error

type HeartbeatListRequest

type HeartbeatListRequest struct {
	pg.OffsetLimit
	Fired *bool `json:"fired,omitempty"`
}

HeartbeatListRequest is the request type for listing heartbeats.

func (HeartbeatListRequest) Select

func (h HeartbeatListRequest) Select(bind *pg.Bind, op pg.Op) (string, error)

type HeartbeatMarkFiredSelector

type HeartbeatMarkFiredSelector string

HeartbeatMarkFiredSelector selects a heartbeat by ID for the mark-fired update.

func (HeartbeatMarkFiredSelector) Select

func (id HeartbeatMarkFiredSelector) Select(bind *pg.Bind, op pg.Op) (string, error)

type HeartbeatMeta

type HeartbeatMeta struct {
	Message  string   `json:"message"`
	Schedule TimeSpec `json:"schedule"`
}

func (HeartbeatMeta) Insert

func (h HeartbeatMeta) Insert(bind *pg.Bind) (string, error)

func (HeartbeatMeta) Update

func (h HeartbeatMeta) Update(bind *pg.Bind) error

type TimeSpec

type TimeSpec struct {
	// Year constrains the four-digit calendar year (e.g. 2026). nil = any year.
	Year *int `json:"year,omitempty"`

	// Month constrains the month as numbers 1–12. Empty = any month.
	Month []int `json:"month,omitempty"`

	// Day constrains the day-of-month 1–31. Empty = any day.
	Day []int `json:"day,omitempty"`

	// Weekday constrains the day-of-week: 0 = Sunday … 6 = Saturday. Empty = any.
	Weekday []int `json:"weekday,omitempty"`

	// Hour constrains the hour 0–23. Empty = any hour.
	Hour []int `json:"hour,omitempty"`

	// Minute constrains the minute 0–59. Empty = any minute.
	Minute []int `json:"minute,omitempty"`

	// Loc is the timezone used when evaluating Next. nil means UTC.
	Loc *time.Location `json:"-"`
}

TimeSpec describes a recurring or one-shot schedule using cron-like fields. Each slice field constrains the schedule to the listed values; an empty slice means "any value matches" (wildcard). Multiple values in a slice are treated as OR — the time only needs to match one of them. TimeSpec.Next returns the earliest matching moment on or after a given time.

func NewTimeSpec

func NewTimeSpec[T time.Time | string](v T, loc *time.Location) (TimeSpec, error)

NewTimeSpec creates a TimeSpec from either a time.Time (one-shot, all fields pinned) or a cron string (5-field: "minute hour day month weekday"). loc is the timezone used when evaluating Next; nil means UTC.

Cron field syntax per field:

  • — any value (wildcard) n — exact value n,m,... — list of values n-m — inclusive range */step — every step-th value across the full range n-m/step — every step-th value within n–m

Examples:

NewTimeSpec[time.Time](t, nil)                        → one-shot at the exact minute of t (UTC)
NewTimeSpec[string]("0 9 * * 1-5", nil)               → 09:00 every weekday UTC
NewTimeSpec[string]("0 9 * * 1-5", londonLoc)         → 09:00 every weekday London time
NewTimeSpec[string]("*/15 * * * *", nil)               → every 15 minutes
NewTimeSpec[string]("30 14 15 6 * 2030", nil)          → 14:30 on 15 June 2030 (6-field, pinned year)

func (TimeSpec) IsZero

func (ts TimeSpec) IsZero() bool

IsZero returns true if ts has no constraints

func (TimeSpec) MarshalJSON

func (ts TimeSpec) MarshalJSON() ([]byte, error)

MarshalJSON serialises TimeSpec as {"schedule":"...","timezone":"..."} (timezone field omitted when UTC/unset), preserving all information through a round-trip.

func (TimeSpec) Next

func (ts TimeSpec) Next(from time.Time) time.Time

Next returns the earliest time on or after from that satisfies every field of ts. The returned time is expressed in ts.Loc (UTC if nil). Returns the zero time.Time when no match exists within a four-year window (e.g. an impossible Day+Weekday combination).

func (TimeSpec) String

func (ts TimeSpec) String() string

String returns the cron expression for this TimeSpec. Recurring schedules produce a 5-field expression: "minute hour day-of-month month day-of-week". One-shot schedules with a pinned year produce a 6-field expression: "minute hour day-of-month month day-of-week year".

func (*TimeSpec) UnmarshalJSON

func (ts *TimeSpec) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts the canonical {"schedule":"...","timezone":"..."} envelope.

Jump to

Keyboard shortcuts

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