Resque::Worker - Does the hard work of babysitting Resque::Job's
The Resque object running this worker.
Queues this worker should fetch jobs from.
Unique identifier for the running worker. Used to set process status all around.
The worker stringify to this attribute.
Set to a true value to make this worker report what's doing while on work().
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.
PID of current running child.
When true, this worker will shutdown after finishing current job.
When true, this worker won't proccess more jobs till false.
Float representing the polling frequency. The default is 5 seconds, but for a semi-active app you may want to use a smaller value.
Stop processing jobs after the current one has completed (if we're currently running one).
Start processing jobs again after a pause
Schedule this worker for shutdown. Will finish processing the current job.
Kill the child and shutdown immediately.
Calling this method will make this worker start pulling & running jobs from queues().
This is the main wheel and will run while shutdown() is false.
Perform() one job and wait till it finish.
Call perform() on the given Resque::Job capturing and reporting any exception.
$worker->perform( $job );
Kills the forked child immediately, without remorse. The job it is processing will not be completed.
Add a queue this worker should listen to.
$worker->add_queue( "queuename" );
Stop listening to the given queue.
$worker->del_queue( "queuename" );
Pull the next job to be precessed.
my $job = $worker->reserve();
Set worker and working status on the given Resque::Job.
$job->working_on( $resque_job );
Inform the backend this worker has done its current job
What time did this worker start? Returns an instance of DateTime.
my $datetime = $worker->started();
Tell Redis we've started
Returns a hash explaining the Job we're currently processing, if any.
What time did this worker started to work on current job? Returns an instance of DateTime or undef when it's not working.
my $datetime = $worker->processing_started();
Returns a string representing the current worker state, which can be either working or idle
my $state = $worker->state();
Boolean - true if working, false if not
my $working = $worker->is_working();
Boolean - true if idle, false if not
my $idle = $worker->is_idle();
Given a string, sets the procline ($0) and logs. Procline is always in the format of: resque-VERSION: STRING
$worker->procline( "string" );
Helper method called by work() to:
1. register_signal_handlers() 2. prune_dead_workers(); 3. register_worker();
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
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.
Registers ourself as a worker. Useful when entering the worker lifecycle on startup.
Unregisters ourself as a worker. Useful when shutting down.
Returns an Array of string pids of all the other workers on this machine. Useful when pruning dead workers on startup.
my @pids = $worker->worker_pids();
If verbose() is true, this will print to STDERR.
$worker->log( 'message here' );
Retrieve from Resque::Stat many jobs has done this worker. Pass a true argument to increment by one before retrieval.
my $jobs_run = $worker->processed( $boolean );
How many failed jobs has this worker seen. Pass a true argument to increment by one before retrieval.
my $jobs_run = $worker->processed( $boolean );
Returns a single worker object. Accepts a string id.
my $worker_object = $worker->find( $worker_id );
Returns a list of all worker registered on the backend, or an arrayref in scalar context;
my @workers = $worker->all();
Returns true if the given worker id exists on redis() backend.
my $exists = $worker->exists( $worker_id );
Diego Kuperman <firstname.lastname@example.org>
This software is copyright (c) 2015 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.