wakes

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 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 wakes matches the wakes on tasks against time, events and their conditions, and emits task.woke for the profile's workflows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	Store Store
	Tasks Tasks
	// Holds says whether a wake's When holds; nil: no condition holds.
	Holds Holds
	Clock port.Clock
}

Deps are what the wakes run on.

type Holds

type Holds func(ctx context.Context, w wake.Wake, t task.Task) (bool, error)

Holds says whether wake w's When holds over task t's facts; injected, so the core matches a condition without importing the package that evaluates the profile's predicates.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service matches the wakes: a wake whose Until passed, whose When holds or one of whose On an event matches wakes its task; one whose Expires passed first is dropped unmatched. Waking records task.woke on the task, with the wake's Return as its data, and spends the wake: it keeps only its Return, which matches nothing, for the profile's wake workflow to read.

func New

func New(d Deps) *Service

New is the wakes over d.

func (*Service) Event

func (s *Service) Event(ctx context.Context, id task.ID, kind, actor string) error

Event matches the wake of task id against an event of kind by actor on the task or a unit it holds.

func (*Service) Next

func (s *Service) Next(ctx context.Context) (time.Time, error)

Next is the earliest Until or Expires of the wakes after now; zero when none.

func (*Service) Sweep

func (s *Service) Sweep(ctx context.Context) error

Sweep wakes or drops the wakes due at now and wakes those whose condition holds. A wake whose task is gone or closed is dropped.

type Store

type Store interface {
	// Put sets the task's wake, replacing the one it had.
	Put(ctx context.Context, w wake.Wake) error
	// Drop removes the task's wake; dropping none is no error.
	Drop(ctx context.Context, id task.ID) error
	// Of is task id's wake, false when it has none.
	Of(ctx context.Context, id task.ID) (wake.Wake, bool, error)
	// Due are the wakes whose Until or Expires is set and not after now,
	// ordered by task id.
	Due(ctx context.Context, now time.Time) ([]wake.Wake, error)
	// Watching are the wakes with On or When set, which events and fact
	// changes match, ordered by task id.
	Watching(ctx context.Context) ([]wake.Wake, error)
}

Store keeps one wake per task.

type Tasks

type Tasks interface {
	Task(ctx context.Context, id task.ID) (task.Task, error)
	Apply(ctx context.Context, cs []task.Change, evs ...port.Event) error
}

Tasks are the tasks the wakes are on, and where a matched wake's task.woke event is recorded. Task fails with tasks.ErrNoTask for a task it does not hold.

Directories

Path Synopsis
Package wakestest holds an in-memory wakes.Store and the suite every wakes store passes.
Package wakestest holds an in-memory wakes.Store and the suite every wakes store passes.

Jump to

Keyboard shortcuts

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