Documentation ¶
Overview ¶
Package mongoqueue provides a job queue, which uses Mongo as a backend storage engine. It supports a sophisticated feature set, facilitating fine-grained job queueing.
Index ¶
- type MongoQueue
- func (q *MongoQueue) Add(x interface{}, id string, p int) (string, error)
- func (q *MongoQueue) Cleanup() error
- func (q *MongoQueue) Complete(id string) error
- func (q *MongoQueue) Count() (c int, err error)
- func (q *MongoQueue) CountFree() (c int, err error)
- func (q *MongoQueue) Fail(id string) error
- func (q *MongoQueue) Lock(pid string) (string, interface{}, error)
- func (q *MongoQueue) MassLock(pid string, n int) ([]string, []interface{}, error)
- func (q *MongoQueue) Pop() (string, interface{}, error)
- func (q *MongoQueue) Stats() (*MongoQueueStats, error)
- func (q *MongoQueue) Truncate() error
- type MongoQueueSettings
- type MongoQueueStats
- type MongoScheduleJobs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MongoQueue ¶
type MongoQueue struct { C *mgo.Collection Settings *MongoQueueSettings MongoSession *mgo.Session }
func NewMongoQueue ¶
func NewMongoQueue(database, queue, server string, settings *MongoQueueSettings) *MongoQueue
func (*MongoQueue) Add ¶
func (q *MongoQueue) Add(x interface{}, id string, p int) (string, error)
Adds a new job in the queue. Higher priority number means higher priority In order to make the queue to act as FIFO instead of a priority queue, specify for all jobs priority 0
func (*MongoQueue) Cleanup ¶
func (q *MongoQueue) Cleanup() error
Cleanup seeks for jobs where the lock has expired, and releases it
func (*MongoQueue) Complete ¶
func (q *MongoQueue) Complete(id string) error
Complete call removes the job from the priority queue
func (*MongoQueue) Count ¶
func (q *MongoQueue) Count() (c int, err error)
Returns the total number of tasks in the queue
func (*MongoQueue) CountFree ¶
func (q *MongoQueue) CountFree() (c int, err error)
Returns the total number of free jobs in the queue
func (*MongoQueue) Fail ¶
func (q *MongoQueue) Fail(id string) error
Marks a job as failed, and keeps in the queue for re-execution at a later stage
func (*MongoQueue) Lock ¶
func (q *MongoQueue) Lock(pid string) (string, interface{}, error)
Lock gets the top-most job from the Priority Queue, and locks it to a worker. The job is not deleted from the queue unless it is marked as completed.
func (*MongoQueue) MassLock ¶
func (q *MongoQueue) MassLock(pid string, n int) ([]string, []interface{}, error)
MassLock gets the top-most job from the Priority Queue, and locks it to a worker. The job is not deleted from the queue unless it is marked as completed. It locks and returns N results
func (*MongoQueue) Pop ¶
func (q *MongoQueue) Pop() (string, interface{}, error)
Pop removes the top-most job from the Priority queue, and returns it back.
func (*MongoQueue) Truncate ¶
func (q *MongoQueue) Truncate() error
Drops all outstanding tasks in the queue
type MongoQueueSettings ¶
type MongoQueueSettings struct { Cleanup int // The interval for the cleanup process LockLimit int // The maximum number of seconds a job can remain locked to a pid // Retry parameters RetryLimit int // The maximum number of retry attempts for a failed task MinBackoff int // The minimum number of seconds to wait before retrying a task after it fails. MaxBackoff int // The maximum number of seconds to wait before retrying a task after it fails. MaxDoublings int // The maximum number of times that the interval between failed task retries will be doubled before the increase becomes constant. The constant is: 2**(max_doublings - 1) * min_backoff_seconds. AgeLimit int // The time limit for retrying a failed task, in seconds, measured from the time the task was created. }
type MongoQueueStats ¶
type MongoScheduleJobs ¶
func NewMongoScheduleJobs ¶
func NewMongoScheduleJobs(database, server string) (*MongoScheduleJobs, error)
func (*MongoScheduleJobs) DeleteJob ¶
func (m *MongoScheduleJobs) DeleteJob(name string)
func (*MongoScheduleJobs) ScheduleJob ¶
func (m *MongoScheduleJobs) ScheduleJob(name string, queue string, x interface{}, p int, interval int64)
func (*MongoScheduleJobs) Start ¶
func (m *MongoScheduleJobs) Start()