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 ¶
- type CondDef
- type DB
- type Machine
- func (m *Machine) EmailSendAllowed(ctx context.Context, condKey string, run bool) error
- func (m *Machine) GenerationAllowed(ctx context.Context, area model.PlanningGate) error
- func (m *Machine) Mark(ctx context.Context, key string)
- func (m *Machine) SetCondition(ctx context.Context, key string, done bool) (*model.PlanningState, error)
- func (m *Machine) State(ctx context.Context) (*model.PlanningState, error)
- func (m *Machine) Unmark(ctx context.Context, key string)
- type PhaseDef
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 (*Machine) EmailSendAllowed ¶
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 ¶
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 ¶
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.