Documentation ¶
Overview ¶
Package task contains a default implementation of the interfaces in the task package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CancelFlag ¶
type CancelFlag interface { // Canceled returns true if a cancel or Shutdown has been requested, false otherwise. // This method should be called periodically in the job. Canceled() bool // Set sets the state of this flag and wakes up waiting callers. Set(state State) // ShutDown returns true if a ShutDown has been requested, false otherwise. // This method should be called periodically in the job. ShutDown() bool // State returns the current flag state State() State // Wait blocks the caller until either a cancel has been requested or the // task has completed normally. Returns Canceled if cancel has been requested, // or Completed if the task completed normally. // This is intended to be used to wake up a job that may be waiting on some resources, as follows: // The main job starts a go routine that calls Wait. The main job then does its processing. // During processing the job may be waiting on certain events/conditions. // In the go routine, once Wait returns, if the return value indicates that a cancel // request has been received, the go routine wakes up the running job. Wait() (state State) }
CancelFlag is an object that is passed to any job submitted to a task in order to communicated job cancellation. Job cancellation has to be cooperative.
type ChanneledCancelFlag ¶
type ChanneledCancelFlag struct {
// contains filtered or unexported fields
}
ChanneledCancelFlag is a default implementation of the task.CancelFlag interface.
func NewChanneledCancelFlag ¶
func NewChanneledCancelFlag() *ChanneledCancelFlag
NewChanneledCancelFlag creates a new instance of ChanneledCancelFlag.
func (*ChanneledCancelFlag) Canceled ¶
func (t *ChanneledCancelFlag) Canceled() bool
Canceled returns true if this flag has been set to Cancel state, false otherwise.
func (*ChanneledCancelFlag) Set ¶
func (t *ChanneledCancelFlag) Set(state State)
Set sets the state of this flag and wakes up waiting callers.
func (*ChanneledCancelFlag) ShutDown ¶
func (t *ChanneledCancelFlag) ShutDown() bool
ShutDown returns true if this flag has been set to ShutDown state, false otherwise.
func (*ChanneledCancelFlag) State ¶
func (t *ChanneledCancelFlag) State() State
State returns the current flag state.
func (*ChanneledCancelFlag) Wait ¶
func (t *ChanneledCancelFlag) Wait() (state State)
Wait blocks until the flag is set to either Cancel or Completed state. Returns the state.
type Job ¶
type Job func(CancelFlag)
Job is a function that receives a cancel flag through which it can be canceled.
type JobStore ¶
type JobStore struct {
// contains filtered or unexported fields
}
JobStore is a collection of jobs.
func (*JobStore) DeleteAllJobs ¶
DeleteAllJobs deletes all the jobs of this task. Returns the deleted jobs.
type JobToken ¶
type JobToken struct {
// contains filtered or unexported fields
}
JobToken embeds a job and its associated info
type MockCancelFlag ¶
MockCancelFlag mocks a cancel flag.
func (*MockCancelFlag) Canceled ¶
func (flag *MockCancelFlag) Canceled() bool
Canceled mocks the method with the same name.
func (*MockCancelFlag) Set ¶
func (flag *MockCancelFlag) Set(state State)
func (*MockCancelFlag) ShutDown ¶
func (flag *MockCancelFlag) ShutDown() bool
ShutDown mocks the method with the same name.
func (*MockCancelFlag) State ¶
func (flag *MockCancelFlag) State() State
func (*MockCancelFlag) Wait ¶
func (flag *MockCancelFlag) Wait() (state State)
Wait mocks the method with the same name.
type MockedPool ¶
MockedPool stands for a mock pool.
func (*MockedPool) Cancel ¶
func (mockPool *MockedPool) Cancel(jobID string) bool
Cancel mocks the method with the same name.
func (*MockedPool) Shutdown ¶
func (mockPool *MockedPool) Shutdown()
Shutdown mocks the method with the same name.
func (*MockedPool) ShutdownAndWait ¶
func (mockPool *MockedPool) ShutdownAndWait(timeout time.Duration) (finished bool)
ShutdownAndWait mocks the method with the same name.
type Pool ¶
type Pool interface { // Submit schedules a job to be executed in the associated worker pool. // Returns an error if a job with the same name already exists. Submit(log log.T, jobID string, job Job) error // Cancel cancels the given job. Jobs that have not started yet will never be started. // Jobs that are running will have their CancelFlag set to the Canceled state. // It is the responsibility of the job to terminate within a reasonable time. // If the job fails to terminate after a Cancel, the job may be abandoned. // Returns true if the job has been found and canceled, false if the job was not found. Cancel(jobID string) bool // Shutdown cancels all the jobs and shuts down the workers. Shutdown() // ShutdownAndWait calls Shutdown then waits until all the workers have exited // or until the timeout has elapsed, whichever comes first. Returns true if all // workers terminated before the timeout or false if the timeout expired. ShutdownAndWait(timeout time.Duration) (finished bool) }
Pool is a pool of jobs.