job

package
v0.0.0-...-aa03a8f Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2016 License: Apache-2.0, BSD-3-Clause, CC-BY-3.0, + 3 more Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

func Reschedule

func Reschedule(jobID int64)

Reschedule is called by statemachine to retry a job

func Schedule

func Schedule(jobID int64)

Schedule put a job id into job queue.

Types

type ImgPuller

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

ImgPuller was for testing

func (ImgPuller) Enter

func (ip ImgPuller) Enter() (string, error)

Enter ...

func (ImgPuller) Exit

func (ip ImgPuller) Exit() error

Exit ...

type ImgPusher

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

ImgPusher is a statehandler for testing

func (ImgPusher) Enter

func (ip ImgPusher) Enter() (string, error)

Enter ...

func (ImgPusher) Exit

func (ip ImgPusher) Exit() error

Exit ...

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

func (Retry) Enter

func (jr Retry) Enter() (string, error)

Enter ...

func (Retry) Exit

func (jr Retry) Exit() error

Exit ...

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

func (sm *SM) EnterState(s string) (string, error)

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

func (sm *SM) RemoveTransition(from string, to string)

RemoveTransition removes a transition from transition table of the state machine

func (*SM) Reset

func (sm *SM) Reset(jid int64) error

Reset resets the state machine so it will start handling another job.

func (*SM) Start

func (sm *SM) Start(s string)

Start kicks off the statemachine to transit from current state to s, and moves on It will search the transit map if the next state is "_continue", and will enter error state if there's more than one possible path when next state is "_continue"

func (*SM) Stop

func (sm *SM) Stop(id int64)

Stop will set the desired state as "stopped" such that when next tranisition happen the state machine will stop handling the current job and the worker can release itself to the workerpool.

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

type StatusUpdater struct {
	JobID int64
	State string
}

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.

func (StatusUpdater) Exit

func (su StatusUpdater) Exit() error

Exit ...

type Worker

type Worker struct {
	ID      int
	RepJobs chan int64
	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.

func NewWorker

func NewWorker(id int) *Worker

NewWorker returns a pointer to new instance of worker

func (*Worker) Start

func (w *Worker) Start()

Start is a loop worker gets id from its channel and handle it.

func (*Worker) Stop

func (w *Worker) Stop()

Stop ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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