NAME
Resque::Worker - Does the hard work of babysitting Resque::Job's
VERSION
version 0.17
ATTRIBUTES
resque
The Resque object running this worker.
queues
Queues this worker should fetch jobs from.
stat
See Resque::Stat.
id
Unique identifier for the running worker. Used to set process status all around.
The worker stringify to this attribute.
verbose
Set to a true value to make this worker report what's doing while on work().
cant_fork
Set it to a true value to stop this worker from fork jobs.
By default, the worker will fork the job out and control the children process. This make the worker more resilient to memory leaks.
child
PID of current running child.
shutdown
When true, this worker will shutdown after finishing current job.
paused
When true, this worker won't proccess more jobs till false.
interval
Float representing the polling frequency. The default is 5 seconds, but for a semi-active app you may want to use a smaller value.
METHODS
pause
Stop processing jobs after the current one has completed (if we're currently running one).
unpause
Start processing jobs again after a pause
shutdown_please
Schedule this worker for shutdown. Will finish processing the current job.
shutdown_now
Kill the child and shutdown immediately.
work
Calling this method will make this worker to start pulling & running jobs from queues().
This is the main wheel and will run while shutdown() is false.
work_tick
Perform() one job and wait till it finish.
perform
Call perform() on the given Resque::Job capturing and reporting any exception.
kill_child
Kills the forked child immediately, without remorse. The job it is processing will not be completed.
add_queue
Add a queue this worker should listen to.
del_queue
Stop listening to the given queue.
reserve
Pull the next job to be precessed.
working_on
Set worker and working status on the given Resque::Job.
done_working
Inform the backend this worker has done its current job
started
What time did this worker start? Returns an instance of DateTime.
TODO: not working in this release. This is returning a string used internally.
set_started
Tell Redis we've started
processing
Returns a hash explaining the Job we're currently processing, if any.
state
Returns a string representing the current worker state, which can be either working or idle
is_working
Boolean - true if working, false if not
is_idle
Boolean - true if idle, false if not
procline
Given a string, sets the procline ($0) and logs. Procline is always in the format of: resque-VERSION: STRING
startup
Helper method called by work() to:
1. register_signal_handlers()
2. prune_dead_workers();
3. register_worker();
register_signal_handlers
Registers the various signal handlers a worker responds to.
TERM: Shutdown immediately, stop processing jobs.
INT: Shutdown immediately, stop processing jobs.
QUIT: Shutdown after the current job has finished processing.
USR1: Kill the forked child immediately, continue processing jobs.
USR2: Don't process any new jobs
CONT: Start processing jobs again after a USR2
prune_dead_workers
Looks for any workers which should be running on this server and, if they're not, removes them from Redis.
This is a form of garbage collection. If a server is killed by a hard shutdown, power failure, or something else beyond our control, the Resque workers will not die gracefully and therefore will leave stale state information in Redis.
By checking the current Redis state against the actual environment, we can determine if Redis is old and clean it up a bit.
register_worker
Registers ourself as a worker. Useful when entering the worker lifecycle on startup.
unregister_worker
Unregisters ourself as a worker. Useful when shutting down.
worker_pids
Returns an Array of string pids of all the other workers on this machine. Useful when pruning dead workers on startup.
log
If verbose() is true, this will print to STDERR.
processed
Retrieve from Resque::Stat many jobs has done this worker. Pass a true argument to increment by one.
failed
How many failed jobs has this worker seen. Pass a true argument to increment by one.
find
Returns a single worker object. Accepts a string id.
all
Returns all worker registered on the backend.
exists
Returns true if the given worker id exists on redis() backend.
AUTHOR
Diego Kuperman <diego@freekeylabs.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Diego Kuperman.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.