resque API reference
Background jobs on Redis, wire-compatible with Resque. Schedule a job onto a named queue now (enqueue), reserve and run it from a worker later (reserve). The Redis layout is the de-facto Resque standard - queues are lists at resque:queue:NAME, the queue registry is a set at resque:queues, and a job is the JSON envelope {"class":"WorkerName","args":[...]} - so a job Jennifer enqueues can be processed by a Ruby-resque / php-resque worker and vice versa. args is a list of string mapping to Ruby-resque's positional arguments; the class string is resolved on the worker's side. Built on the redis module, so it needs the default jennifer binary.
Import with import "resque.j" as resque;. See the resque guide for prose and examples.
Contents
| Name | What it is |
|---|---|
enqueue | Schedule a job: register the queue, then push the envelope onto it. |
fail | Record a failed job on the failed list (a simplified failure entry). |
queueLength | Return the number of pending jobs on one queue. |
queues | Return the registered queue names. |
reserve | Pop the next job from the first non-empty queue, checking queues in the given priority order. |
reserveBlocking | Reserve the next job, BLOCKING on the given queues until one has work or timeoutSec elapses (Redis... |
size | Return the total number of pending jobs across every registered queue. |
Job | struct: A reserved job. |
Functions
enqueue
resque.enqueue(
session as redis.Session,
queue as string,
class as string,
args as list of string)Schedule a job: register the queue, then push the envelope onto it.
session- the open Redis session
queue- the queue name to push onto
class- the worker class the job names
args- the job's positional arguments
fail
resque.fail(session as redis.Session, job as Job, message as string)Record a failed job on the failed list (a simplified failure entry).
session- the open Redis session
job- the job that failed
message- the failure message
queueLength
resque.queueLength(session as redis.Session, queue as string)Return the number of pending jobs on one queue.
session- the open Redis session
queue- the queue name
- Returns
int - the number of pending jobs
queues
resque.queues(session as redis.Session)Return the registered queue names.
session- the open Redis session
- Returns
list of string - the registered queue names
reserve
resque.reserve(session as redis.Session, queues as list of string)Pop the next job from the first non-empty queue, checking queues in the given priority order.
session- the open Redis session
queues- the queue names to check, in priority order
- Returns
Job - the reserved job, or an empty
Job(class"") when all drained
reserveBlocking
resque.reserveBlocking(
session as redis.Session,
queues as list of string,
timeoutSec as int)Reserve the next job, BLOCKING on the given queues until one has work or timeoutSec elapses (Redis BLPOP) instead of polling with reserve. A worker loop parks on the socket rather than spinning. Queues are honoured in priority order (BLPOP returns from the first non-empty). timeoutSec 0 blocks indefinitely (Redis semantics).
session- the open Redis session
queues- the queue names to watch, in priority order
timeoutSec- seconds to block; 0 blocks until a job arrives
- Returns
Job - the reserved job, or an empty
Job(class"") on timeout
size
resque.size(session as redis.Session)Return the total number of pending jobs across every registered queue.
session- the open Redis session
- Returns
int - the total number of pending jobs
Structs
Job
A reserved job. A drained reserve returns an empty Job (class is "").
def struct Job {
queue as string,
class as string,
args as list of string
};queue- the origin queue the job came from
class- the worker class to run
args- the job's positional string arguments