Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var WorkerPool *workerPool
WorkerPool is a set of workers each worker is associate to a statemachine for handling jobs. it consists of a channel for free workers and a list to all workers
Functions ¶
func Dispatch ¶
func Dispatch()
Dispatch will listen to the jobQueue of job service and try to pick a free worker from the worker pool and assign the job to it.
func InitWorkerPool ¶
func InitWorkerPool()
InitWorkerPool create workers according to configuration.
Types ¶
type ImgPuller ¶
type ImgPuller struct {
// contains filtered or unexported fields
}
ImgPuller was for testing
type ImgPusher ¶
type ImgPusher struct {
// contains filtered or unexported fields
}
ImgPusher is a statehandler for testing
type RepJobParm ¶
type RepJobParm struct { LocalRegURL string TargetURL string TargetUsername string TargetPassword string Repository string Tags []string Enabled int Operation string Insecure bool }
RepJobParm wraps the parm of a job
type Retry ¶
type Retry struct {
JobID int64
}
Retry handles a special "retrying" in which case it will update the status in DB and reschedule the job via scheduler
type SM ¶
type SM struct { JobID int64 CurrentState string PreviousState string //The states that don't have to exist in transition map, such as "Error", "Canceled" ForcedStates map[string]struct{} Transitions map[string]map[string]struct{} Handlers map[string]StateHandler Logger *log.Logger Parms *RepJobParm // contains filtered or unexported fields }
SM is the state machine to handle job, it handles one job at a time.
func (*SM) AddTransition ¶
func (sm *SM) AddTransition(from string, to string, h StateHandler)
AddTransition add a transition to the transition table of state machine, the handler is the handler of target state "to"
func (*SM) EnterState ¶
EnterState transit the statemachine from the current state to the state in parameter. It returns the next state the statemachine should tranit to.
func (*SM) Init ¶
func (sm *SM) Init()
Init initialzie the state machine, it will be called once in the lifecycle of state machine.
func (*SM) RemoveTransition ¶
RemoveTransition removes a transition from transition table of the state machine
type StateHandler ¶
type StateHandler interface { // Enter returns the next state, if it returns empty string the SM will hold the current state or // or decide the next state. Enter() (string, error) //Exit should be idempotent Exit() error }
StateHandler handles transition, it associates with each state, will be called when SM enters and exits a state during a transition.
type StatusUpdater ¶
StatusUpdater implements the StateHandler interface which updates the status of a job in DB when the job enters a status.
func (StatusUpdater) Enter ¶
func (su StatusUpdater) Enter() (string, error)
Enter updates the status of a job and returns "_continue" status to tell state machine to move on. If the status is a final status it returns empty string and the state machine will be stopped.
type Worker ¶
Worker consists of a channel for job from which worker gets the next job to handle, and a pointer to a statemachine, the actual work to handle the job is done via state machine.