Documentation ¶
Index ¶
- Variables
- func Dispatch()
- func GetJobLogPath(base string, jobID int64) string
- func InitWorkerPools() error
- func NewLogger(j Job) (*log.Logger, error)
- func Reschedule(j Job)
- func Schedule(j Job)
- type ImgPuller
- type ImgPusher
- type Job
- type RepJob
- type RepJobParm
- type Retry
- type SM
- type ScanJob
- type ScanJobParm
- type StateHandler
- type StatusUpdater
- type Type
- type Worker
Constants ¶
This section is empty.
Variables ¶
var WorkerPools map[Type]*workerPool
WorkerPools is a map contains workerpools for different types of jobs.
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 GetJobLogPath ¶
GetJobLogPath returns the absolute path in which the job log file is located.
func InitWorkerPools ¶
func InitWorkerPools() error
InitWorkerPools create worker pools for different types of jobs.
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 Job ¶
type Job interface { //ID returns the id of the job ID() int64 Type() Type LogPath() string UpdateStatus(status string) error GetStatus() (string, error) Init() error }
Job is abstraction for image replication and image scan jobs.
type RepJob ¶
type RepJob struct {
// contains filtered or unexported fields
}
RepJob implements Job interface, represents a replication job.
func NewRepJob ¶
NewRepJob returns a pointer to RepJob which implements the Job interface. Given API only gets the id, it will call this func to get a instance that can be manuevered by state machine.
type RepJobParm ¶
type RepJobParm struct { LocalRegURL string TargetURL string TargetUsername string TargetPassword string Repository string Tags []string Operation string Insecure bool }
RepJobParm wraps the parm of a replication job
type Retry ¶
type Retry struct {
Job Job
}
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 { CurrentJob Job 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 // 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
func (*SM) Reset ¶
Reset resets the state machine and after prereq checking, it will start handling the job.
type ScanJob ¶
type ScanJob struct {
// contains filtered or unexported fields
}
ScanJob implements the Job interface, representing a job for scanning image.
func NewScanJob ¶
NewScanJob creates a instance of ScanJob by id.
func (*ScanJob) Init ¶
Init query the DB and populate the information of the image to scan in the parm of this job.
func (*ScanJob) LogPath ¶
LogPath returns the absolute path of the log file for the job, log files for scan job will be put in a sub folder of base log path.
func (*ScanJob) UpdateStatus ¶
UpdateStatus ...
type ScanJobParm ¶
ScanJobParm wraps the parms of a image scan job.
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 ¶
type Worker struct { ID int Type Type Jobs chan Job SM *SM // contains filtered or unexported fields }
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.