Documentation ¶
Index ¶
- Constants
- Variables
- func Configure(opts *Options)
- func Register(queue string, numWorkers int, f HandlerFunc)
- func WorkForever()
- type Canceller
- type Client
- func (c *Client) CreateJob(payload interface{}) (Job, error)
- func (c *Client) Job(id int) (Job, error)
- func (c *Client) Register(queue Queue, f HandlerFunc)
- func (c *Client) Submit(queue Queue, priority int, payload interface{}) (Job, error)
- func (c *Client) SubmitDelayed(queue Queue, d time.Duration, payload interface{}) (Job, error)
- func (c *Client) SubmitDelayedJob(queue Queue, d time.Duration, job Job) (Job, error)
- func (c *Client) SubmitJob(queue Queue, priority int, job Job) (Job, error)
- func (c *Client) Work() Canceller
- func (c *Client) WorkForever()
- type Conn
- type HandlerFunc
- type Job
- type JobState
- type Options
- type Queue
Constants ¶
const ( // Initial jobs are created jobs, but not associated with a queue. Initial JobState = 0 // Queued jobs are in a queue, waiting to be processed. Queued = 1 // Working jobs are currently being processed. Working = 2 // Finished jobs that have completed successfully Finished = 3 // Dead jobs are jobs that have failed > Qeuue.MaxAttempts Dead = 4 )
Variables ¶
var DefaultClient = NewClient(nil)
DefaultClient is the Client used by the package-level functions.
Functions ¶
func Register ¶
func Register(queue string, numWorkers int, f HandlerFunc)
Register a given HandlerFunc with a queue
func WorkForever ¶
func WorkForever()
WorkForever will being processing registered queues. This routine will block until SIGINT is received.
Types ¶
type Canceller ¶
Canceller allows the user to cancel all working jobs. If timeout is not set, all currently working jobs will immediately be marked failed.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a managed koda client. Users should not attempt instantiate their own Client, but instead should use NewClient.
func (*Client) Register ¶
func (c *Client) Register(queue Queue, f HandlerFunc)
Register a HandlerFunc for a given Queue
func (*Client) SubmitDelayed ¶
SubmitDelayed creates a job and puts it on the delayed queue.
func (*Client) SubmitDelayedJob ¶
SubmitDelayedJob puts an existing job on the delayed queue.
func (*Client) Work ¶
Work will begin processing any registered queues in a separate goroutine. Use returned Canceller to stop any outstanding workers.
func (*Client) WorkForever ¶
func (c *Client) WorkForever()
WorkForever will being processing registered queues. This routine will block until SIGINT is received.
type Conn ¶
type Conn interface { Incr(key string) (int, error) // TODO: Update this to return a map[string]string HGetAll(key string) ([]string, error) HSetAll(key string, fields map[string]string) error RPush(key string, value ...string) (int, error) BLPop(timeout time.Duration, keys ...string) ([]string, error) ZAddNX(key string, score float64, member string) (int, error) // ZPopByScore has the same interface as ZRANGEBYSCORE, but also removes each member ZPopByScore(key string, min, max float64, minIncl, maxIncl bool, offset, count int) ([]string, error) Subscribe(channel string) (<-chan string, error) Close() error }
Conn may be implemented by custom redis connections. See Options.ConnFactory. Note to implementers, each function must be atomic.
type HandlerFunc ¶
HandlerFunc is used when registering a worker for a queue. If an error is returned, the job will be marked as failed. If Job.NumAttempts exceeds Queue.MaxAttempts, the job is placed in the Dead state. Otherwise it is placed on the delayed queue with a delay of Queue.RetryInterval
type Job ¶
type Job struct { ID int State JobState DelayedUntil time.Time CreationTime time.Time CompletionTime time.Time Priority int NumAttempts int // contains filtered or unexported fields }
Job represents a koda job. Job should not be instantiated directly. Instead use Client.CreateJob, Client.Submit and Client.SubmitDelayed to create a Job.
func SubmitDelayed ¶
SubmitDelayed creates a job and puts it on the delayed queue.
func (*Job) UnmarshalPayload ¶
UnmarshalPayload will unmarshal the associated payload into v.
type Options ¶
type Options struct { // Redis URL (format: redis://[auth@]host[:port][/database]) // Default: redis://localhost:6379 URL string // Prefix for redis keys // Default: koda Prefix string ConnFactory func() Conn }
Options for a Client.
type Queue ¶
type Queue struct { Name string // The number of simultaneous workers // Default: 1 NumWorkers int // The maximum number of attempts for a single job. // Default: 1 MaxAttempts int // The interval between attempts // Default: 0 RetryInterval time.Duration // contains filtered or unexported fields }
Queue represesents a configurable queue.