- COPYRIGHT AND LICENSE
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.
Set it to a true value to stop this worker from polling for jobs and use experimental blocking pop instead.
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.
Integer representing the blocking timeout. The default is not to block but to poll queues (see inverval), so this attribute will be completely ignored unless dont_poll(). The default is 30 seconds. Setting it to 0 will make reserve() to block until some job is assigned to this workers and will prevent autoconfig() to be called until it happen.
An optional callback to be called periodically while work()'ing. It's main purpose is to allow running auto-config code as this function will receive this worker as it's only argument and will be called before reserving the first job.
When this callback is provided, it will be called on every wheel iteration, so it's recommended to keep track of time to prevent running slow re-configuration code every time.
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.
Returns a hashref of processing info for a given worker or worker ID list
$worker->processing( $worker1, $worker2, $worker3->id );
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.
Do the dirty work after changing the queues on an already register_worker().
This will update backend on a single transactionto reflex current queues by changing this worker ID which need to unregister_worker() and register_worker() again while keeping stat() and started().
Only useful when you dinamically update queues and want to watch it on the web interface.
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->failed( $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) 2021 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.