Documentation ¶
Index ¶
- Constants
- Variables
- func CancelJob(id string)
- func GetJobStatus(id string) string
- func GetJobsMetrics() map[string]interface{}
- func GetPoolSize() int
- func RecordJobsMetrics(enabled bool)
- func Send(job *Job) string
- func SetLogger(l Logger)
- func SetPoolSize(n int)
- func Shutdown()
- type Job
- type JobAction
- type Logger
- type Workerpool
- func (w *Workerpool) CancelJob(id string)
- func (w *Workerpool) GetJob(id string) *Job
- func (w *Workerpool) GetJobStatus(id string) string
- func (w *Workerpool) GetJobsMetrics() map[string]interface{}
- func (w *Workerpool) GetPoolSize() int
- func (w *Workerpool) RecordJobsMetrics(enabled bool)
- func (w *Workerpool) Send(job *Job) string
- func (w *Workerpool) SetLogger(l Logger)
- func (w *Workerpool) SetPoolSize(n int)
- func (w *Workerpool) Shutdown()
Constants ¶
const ( // PENDING state when job is queued. PENDING = "pending" // RUNNING state when job is currently executed. RUNNING = "running" // COMPLETED state when job is terminated whithout error. COMPLETED = "completed" // FAILED state when job is terminated with error. FAILED = "failed" // CANCELLED state when job is cancelled by the user. CANCELLED = "cancelled" )
Variables ¶
Functions ¶
func CancelJob ¶
func CancelJob(id string)
CancelJob stops the job for the given id in an asynchronous routine.
func GetJobStatus ¶
GetJobStatus returns the job's status for the given id.
func GetJobsMetrics ¶
func GetJobsMetrics() map[string]interface{}
GetJobsMetrics returns the metrics about the workerpool.
func RecordJobsMetrics ¶ added in v0.4.0
func RecordJobsMetrics(enabled bool)
RecordJobsMetrics records or not the metrics about the workerpool.
func SetPoolSize ¶
func SetPoolSize(n int)
SetPoolSize defines the number of wanted workers. n is absolute so the pool can be expanded or shrunk according to n.
Types ¶
type Job ¶
type Job struct { OnStatusChangeFunc JobAction BeforeFunc JobAction ActionFunc JobAction AfterFunc JobAction CancelFunc JobAction // ErrHandler is executed when an error or a panic occur. ErrHandler func(j *Job, err error, panic bool) // contains filtered or unexported fields }
A Job performs actions.
func (*Job) SetContext ¶
SetContext sets the given context to the job. It panics if the job is queued.
type Logger ¶
type Logger interface { Print(...interface{}) Printf(string, ...interface{}) Println(...interface{}) Fatal(...interface{}) Fatalf(string, ...interface{}) Fatalln(...interface{}) Panic(...interface{}) Panicf(string, ...interface{}) Panicln(...interface{}) }
A Logger defines all function needed by the workerpool's logger.
type Workerpool ¶
type Workerpool struct {
// contains filtered or unexported fields
}
A Workerpool manages asynchronous jobs.
func NewDefault ¶
func NewDefault() *Workerpool
NewDefault instanciates a new Workerpool with a queue size of 10k elements.
func (*Workerpool) CancelJob ¶
func (w *Workerpool) CancelJob(id string)
CancelJob stops the job for the given id in an asynchronous routine.
func (*Workerpool) GetJob ¶
func (w *Workerpool) GetJob(id string) *Job
GetJob returns the job for the given id.
func (*Workerpool) GetJobStatus ¶
func (w *Workerpool) GetJobStatus(id string) string
GetJobStatus returns the job's status for the given id.
func (*Workerpool) GetJobsMetrics ¶
func (w *Workerpool) GetJobsMetrics() map[string]interface{}
GetJobsMetrics returns the metrics about the workerpool.
func (*Workerpool) GetPoolSize ¶
func (w *Workerpool) GetPoolSize() int
GetPoolSize returns the number of running workers.
func (*Workerpool) RecordJobsMetrics ¶ added in v0.4.0
func (w *Workerpool) RecordJobsMetrics(enabled bool)
RecordJobsMetrics records or not the metrics about the workerpool.
func (*Workerpool) Send ¶
func (w *Workerpool) Send(job *Job) string
Send enqueues the given job and returns its ID.
func (*Workerpool) SetLogger ¶
func (w *Workerpool) SetLogger(l Logger)
SetLogger defines the workerpool logger.
func (*Workerpool) SetPoolSize ¶
func (w *Workerpool) SetPoolSize(n int)
SetPoolSize defines the number of wanted workers. n is absolute so the pool can be expanded or shrunk according to n.
func (*Workerpool) Shutdown ¶
func (w *Workerpool) Shutdown()
Shutdown waits job completion and shrink the pool to 0.