planstate

package
v1.215.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: BSD-3-Clause Imports: 4 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 planstate is the generic planning-state engine: a 1-safe condition/event Petri net where each condition is a milestone that can be set automatically (Mark) or by hand (SetCondition), and a condition with a gate locks the matching generation while it is set. The concrete net (which conditions/phases/gates exist) is policy and is injected by the caller (plexams); this package only implements the mechanism over a small DB interface (satisfied by *db.DB).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CondDef

type CondDef struct {
	Key   string
	Title string
	Phase string
	Gate  model.PlanningGate
}

CondDef declares one planning condition (milestone). Gate, if not empty, is the area locked while this condition is set.

type DB

type DB interface {
	PlanningConditionsSet(ctx context.Context) ([]string, error)
	SetPlanningCondition(ctx context.Context, key string, set bool) error
}

DB is the persistence the engine needs; *db.DB satisfies it.

type Machine

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

Machine is a planning-state engine over an injected net.

func New

func New(db DB, phases []PhaseDef, conds []CondDef) *Machine

New builds the engine for the given net.

func (*Machine) EmailSendAllowed

func (m *Machine) EmailSendAllowed(ctx context.Context, condKey string, run bool) error

EmailSendAllowed enforces that a "send once" email is sent at most once: while its condition is set, a real send (run==true) is refused; a dry run (run==false) is always allowed. On a successful real send the caller marks the condition. To resend, the condition has to be unset by hand.

func (*Machine) GenerationAllowed

func (m *Machine) GenerationAllowed(ctx context.Context, area model.PlanningGate) error

GenerationAllowed reports whether generation for the given area is allowed, i.e. no gate condition for that area is set. Returns an error describing the lock otherwise.

func (*Machine) Mark

func (m *Machine) Mark(ctx context.Context, key string)

Mark sets a condition as done. Best-effort: a failure is logged but never fails the operation that triggered it.

func (*Machine) SetCondition

func (m *Machine) SetCondition(ctx context.Context, key string, done bool) (*model.PlanningState, error)

SetCondition sets or clears a condition by hand. Errors on an unknown key.

func (*Machine) State

func (m *Machine) State(ctx context.Context) (*model.PlanningState, error)

State assembles the current planning state from the declarative net and the conditions stored as set in the DB.

func (*Machine) Unmark

func (m *Machine) Unmark(ctx context.Context, key string)

Unmark clears a condition. Best-effort like Mark.

type PhaseDef

type PhaseDef struct {
	Key   string
	Title string
}

PhaseDef declares one planning phase.

Jump to

Keyboard shortcuts

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