Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

theschwartz::worker(3pm) [debian man page]

TheSchwartz::Worker(3pm)				User Contributed Perl Documentation				  TheSchwartz::Worker(3pm)

NAME
TheSchwartz::Worker - superclass for defining task behavior SYNOPSIS
package MyWorker; use base qw( TheSchwartz::Worker ); sub work { my $class = shift; my TheSchwartz::Job $job = shift; print "Workin' hard or hardly workin'? Hyuk!! "; $job->completed(); } package main; my $client = TheSchwartz->new( databases => $DATABASE_INFO ); $client->can_do('MyWorker'); $client->work(); DESCRIPTION
TheSchwartz::Worker objects are the salt of the reliable job queuing earth. The behavior required to perform posted jobs are defined in subclasses of TheSchwartz::Worker. These subclasses are named for the ability required of a "TheSchwartz" client to do the job, so that the clients can dispatch automatically to the approprate worker routine. Because jobs can be performed by any machine running code for capable worker classes, "TheSchwartz::Worker"s are generally stateless. All mutable state is stored in the "TheSchwartz::Job" objects. This means all "TheSchwartz::Worker" methods are class methods, and "TheSchwartz::Worker" classes are generally never instantiated. SUBCLASSING
Define and customize how a job is performed by overriding these methods in your subclass: "$class->work( $job )" Performs the job that required ability $class. Override this method to define how to do the job you're defining. Note that will need to call "$job->completed()" or "$job->failed()" as appropriate to indicate success or failure. See TheSchwartz::Job. "$class->max_retries( $job )" Returns the number of times workers should attempt the given job. After this many tries, the job is marked as completed with errors (that is, a "TheSchwartz::ExitStatus" is recorded for it) and removed from the queue. By default, returns 0. "$class->retry_delay( $num_failures )" Returns the number of seconds after a failure workers should wait until reattempting a job that has already failed $num_failures times. By default, returns 0. "$class->keep_exit_status_for()" Returns the number of seconds to allow a "TheSchwartz::ExitStatus" record for a job performed by this worker class to exist. By default, returns 0. "$class->grab_for()" Returns the number of seconds workers of this class will claim a grabbed a job. That is, returns the length of the timeout after which other workers will decide a worker that claimed a job has crashed or faulted without marking the job failed. Jobs that are marked as failed by a worker are also marked for immediate retry after a delay indicated by "retry_delay()". USAGE
"$class->grab_job( $client )" Finds and claims a job for workers with ability $class, using "TheSchwartz" client $client. This job can then be passed to "work()" or "work_safely()" to perform it. "$class->work_safely( $job )" Performs the job associated with the worker's class name. If an error is thrown while doing the job, the job is appropriately marked as failed, unlike when calling "work()" directly. perl v5.10.0 2008-03-02 TheSchwartz::Worker(3pm)

Check Out this Related Man Page

Gearman::Worker(3pm)					User Contributed Perl Documentation				      Gearman::Worker(3pm)

NAME
Gearman::Worker - Worker for gearman distributed job system SYNOPSIS
use Gearman::Worker; my $worker = Gearman::Worker->new; $worker->job_servers('127.0.0.1'); $worker->register_function($funcname => $subref); $worker->work while 1; DESCRIPTION
Gearman::Worker is a worker class for the Gearman distributed job system, providing a framework for receiving and serving jobs from a Gearman server. Callers instantiate a Gearman::Worker object, register a list of functions and capabilities that they can handle, then enter an event loop, waiting for the server to send jobs. The worker can send a return value back to the server, which then gets sent back to the client that requested the job; or it can simply execute silently. USAGE
Gearman::Worker->new(%options) Creates a new Gearman::Worker object, and returns the object. If %options is provided, initializes the new worker object with the settings in %options, which can contain: o job_servers Calls job_servers (see below) to initialize the list of job servers. It will be ignored if this worker is running as a child process of a gearman server. o prefix Calls prefix (see below) to set the prefix / namespace. $worker->job_servers(@servers) Initializes the worker $worker with the list of job servers in @servers. @servers should contain a list of IP addresses, with optional port numbers. For example: $worker->job_servers('127.0.0.1', '192.168.1.100:7003'); If the port number is not provided, 7003 is used as the default. Calling this method will do nothing in a worker that is running as a child process of a gearman server. $worker->register_function($funcname, $subref) $worker->register_function($funcname, $timeout, $subref) Registers the function $funcname as being provided by the worker $worker, and advertises these capabilities to all of the job servers defined in this worker. $subref must be a subroutine reference that will be invoked when the worker receives a request for this function. It will be passed a Gearman::Job object representing the job that has been received by the worker. $timeout is an optional parameter specifying how long the jobserver will wait for your subroutine to give an answer. Exceeding this time will result in the jobserver reassigning the task and ignoring your result. This prevents a gimpy worker from ruining the 'user experience' in many situations. The subroutine reference can return a return value, which will be sent back to the job server. $client->prefix($prefix) Sets the namespace / prefix for the function names. This is useful for sharing job servers between different applications or different instances of the same application (different development sandboxes for example). The namespace is currently implemented as a simple tab separated concatentation of the prefix and the function name. Gearman::Job->arg Returns the scalar argument that the client sent to the job server. Gearman::Job->set_status($numerator, $denominator) Updates the status of the job (most likely, a long-running job) and sends it back to the job server. $numerator and $denominator should represent the percentage completion of the job. Gearman::Job->work(%opts) Do one job and returns (no value returned). You can pass "on_start" "on_complete" and "on_fail" callbacks in %opts. WORKERS AS CHILD PROCESSES
Gearman workers can be run run as child processes of a parent process which embeds Gearman::Server. When such a parent process fork/execs a worker, it sets the environment variable GEARMAN_WORKER_USE_STDIO to true before launching the worker. If this variable is set to true, then the jobservers function and option for new() are ignored and the unix socket bound to STDIN/OUT are used instead as the IO path to the gearman server. EXAMPLES
Summation This is an example worker that receives a request to sum up a list of integers. use Gearman::Worker; use Storable qw( thaw ); use List::Util qw( sum ); my $worker = Gearman::Worker->new; $worker->job_servers('127.0.0.1'); $worker->register_function(sum => sub { sum @{ thaw($_[0]->arg) } }); $worker->work while 1; See the Gearman::Client documentation for a sample client sending the sum job. perl v5.10.1 2009-10-05 Gearman::Worker(3pm)
Man Page