Documentation ¶
Overview ¶
Package state implements state machine of a Project Manager.
Index ¶
- func SideEffectFn(s SideEffect) eventbox.SideEffectFn
- type CancelIncompleteRuns
- type RunNotifier
- type SideEffect
- type SideEffects
- type State
- func (s *State) ExecDeferred(ctx context.Context) (_ *State, __ SideEffect, err error)
- func (s *State) OnCLsUpdated(ctx context.Context, clEVersions map[int64]int64) (_ *State, __ SideEffect, err error)
- func (s *State) OnPurgesCompleted(ctx context.Context, events []*prjpb.PurgeCompleted) (_ *State, __ SideEffect, err error)
- func (s *State) OnRunsCreated(ctx context.Context, created common.RunIDs) (_ *State, __ SideEffect, err error)
- func (s *State) OnRunsFinished(ctx context.Context, finished common.RunIDs) (_ *State, __ SideEffect, err error)
- func (s *State) Poke(ctx context.Context) (*State, SideEffect, error)
- func (s *State) UpdateConfig(ctx context.Context) (*State, SideEffect, error)
- func (s *State) UpgradeIfNecessary() *State
- type TriggerPurgeCLTasks
- type UpdateIncompleteRunsConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SideEffectFn ¶
func SideEffectFn(s SideEffect) eventbox.SideEffectFn
Types ¶
type CancelIncompleteRuns ¶
type CancelIncompleteRuns struct { RunNotifier RunNotifier RunIDs common.RunIDs }
CancelIncompleteRuns sends Cancel event to incomplete Runs.
type RunNotifier ¶
type SideEffect ¶
SideEffect describes action to be done transactionally with updating state in Datastore.
It may consist of several `SideEffect`s, which are executed sequentially.
Semantically, this is translatable to eventbox.SideEffectFn, but is easy to assert for in tests of this package.
func NewSideEffects ¶
func NewSideEffects(items ...SideEffect) SideEffect
NewSideEffects returns composite SideEffect.
At least 2 items must be provided. Provided arg slice must not be mutated.
type SideEffects ¶
type SideEffects struct {
// contains filtered or unexported fields
}
SideEffects combines 2+ `SideEffect`s.
type State ¶
type State struct { // PB is the serializable part of State mutated using copy-on-write approach // https://en.wikipedia.org/wiki/Copy-on-write PB *prjpb.PState // LogReasons is append-only accumulation of reasons to record this state for // posterity. LogReasons []prjpb.LogReason // Dependencies used to prepare state transitions. PMNotifier *prjmanager.Notifier RunNotifier RunNotifier CLPurger *clpurger.Purger CLPoller *poller.Poller ComponentTriage itriager.Triage // contains filtered or unexported fields }
State is a state of Project Manager.
The state object must not be re-used except for serializing public state after its public methods returned a modified State or an error. This allows for efficient evolution of cached helper datastructures which would otherwise have to be copied, too.
To illustrate correct and incorrect usages:
s0 := &State{...} s1, _, err := s0.Mut1() if err != nil { // ... := s0.Mut2() // NOT OK, 2nd call on s0 return proto.Marshal(s0.PB) // OK } // ... := s0.Mut2() // NOT OK, 2nd call on s0 s2, _, err := s1.Mut2() // OK, s1 may be s0 if Mut1() was noop if err != nil { // return proto.Marshal(s0.PB) // OK return proto.Marshal(s0.PB) // OK }
func (*State) ExecDeferred ¶
ExecDeferred performs previously postponed actions, notably creating Runs.
func (*State) OnCLsUpdated ¶
func (s *State) OnCLsUpdated(ctx context.Context, clEVersions map[int64]int64) (_ *State, __ SideEffect, err error)
OnCLsUpdated updates state as a result of new changes to CLs.
clEVersions must map CL's ID to CL's EVersion. clEVersions is mutated.
func (*State) OnPurgesCompleted ¶
func (s *State) OnPurgesCompleted(ctx context.Context, events []*prjpb.PurgeCompleted) (_ *State, __ SideEffect, err error)
OnPurgesCompleted updates state as a result of completed purge operations.
func (*State) OnRunsCreated ¶
func (s *State) OnRunsCreated(ctx context.Context, created common.RunIDs) (_ *State, __ SideEffect, err error)
OnRunsCreated updates state after new Runs were created.
For Runs created by PM itself, this should typically be a noop, since adding newly created Run to its component should have been done right after Run creation, unless PM couldn't save its state (e.g. crashed or collided with concurrent PM invocation).
func (*State) OnRunsFinished ¶
func (s *State) OnRunsFinished(ctx context.Context, finished common.RunIDs) (_ *State, __ SideEffect, err error)
OnRunsFinished updates state after Runs were finished.
func (*State) UpdateConfig ¶
UpdateConfig updates PM to the latest config version.
func (*State) UpgradeIfNecessary ¶
UpgradeIfNecessary upgrades old state to new format if necessary.
Returns the new state, or this state if nothing was changed.
type TriggerPurgeCLTasks ¶
type TriggerPurgeCLTasks struct {
// contains filtered or unexported fields
}
TriggerPurgeCLTasks triggers PurgeCLTasks via TQ.
type UpdateIncompleteRunsConfig ¶
type UpdateIncompleteRunsConfig struct { RunNotifier RunNotifier RunIDs common.RunIDs Hash string EVersion int64 }
UpdateIncompleteRunsConfig sends UpdateConfig events to incomplete Runs.