Documentation ¶
Index ¶
Constants ¶
const ( StatusStopped uint32 = iota StatusRunning StatusStopping )
Variables ¶
var InvalidRedisReplyError = errors.New("Invalid redis reply")
Functions ¶
func NewRedisPool ¶
func NewRedisPool(address string, options ...redis.DialOption) *redis.Pool
NewRedisPool creates a new redis pool.
func RandHexString ¶
RandHexString generates a random hex string.
Types ¶
type GoTask ¶
type GoTask struct {
// contains filtered or unexported fields
}
GoTask store a RawGoTask and the serialized data.
func DeserializeGoTask ¶
DeserializeGoTask creates a new GoTask from the serialized data.
func NewGoTaskOfFunc ¶
func NewGoTaskOfFunc(f interface{}, arg ...interface{}) *GoTask
NewGoTaskOfFunc creates a new GoTask by a function. It's about 100x slower than NewGoTask.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
A handler stores a function and other information about how to call it.
func NewHandler ¶
func NewHandler(f interface{}) (h *Handler)
NewHandler creates a handler for a function.
type PyTask ¶
type PyTask struct {
// contains filtered or unexported fields
}
PyTask store a RawPyTask and the serialized data.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is the struct of a task queue.
func NewQueue ¶
func NewQueue(name string, redisPool *redis.Pool, options ...QueueOption) *Queue
NewQueue creates a new queue.
func (*Queue) Release ¶
Release releases the currently dequeued task. It should be called after finishing a task.
func (*Queue) RequeueLost ¶
RequeueLost finds out lost tasks and recovers them. It should be called periodically to prevent losing tasks. The lost tasks were those popped from the queue, but its dead worker hadn't released it.
type QueueOption ¶
type QueueOption func(*Queue)
func DequeueTimeout ¶
func DequeueTimeout(d time.Duration) QueueOption
DequeueTimeout sets the dequeue timeout of a queue. It must be larger than 1 ms, Redis BLPOP treats timeout equal or less than 0.001 second as 0 (forever).
func KeepAliveTimeout ¶
func KeepAliveTimeout(d time.Duration) QueueOption
KeepAliveTimeout sets the keep alive timeout of the worker of a queue.
type RawPyTask ¶
type RawPyTask struct { FuncPath string Args interface{} // must be slice, array or nil KwArgs interface{} // must be map, struct or nil }
RawPyTask store the fields need to be serialized for a PyTask.
type Sweeper ¶
type Sweeper struct {
// contains filtered or unexported fields
}
Sweeper keeps recovering lost tasks.
func (*Sweeper) SetInterval ¶
SetInterval sets the interval of the sweeper.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker keeps dequeuing and processing Go tasks.
func NewWorker ¶
func NewWorker(queue *Queue, options ...WorkerOption) *Worker
NewWorker creates a new worker.
func (*Worker) RegisterHandlers ¶
func (w *Worker) RegisterHandlers(funcs ...interface{})
RegisterHandlers registers handlers. Tasks with function not been registered will be ignored.
type WorkerOption ¶
type WorkerOption func(*Worker)
func KeepAliveDuration ¶
func KeepAliveDuration(d time.Duration) WorkerOption
KeepAliveDuration sets the keep alive duration of a worker.