Gearman::XS::Worker - Perl worker for gearman using libgearman
use Gearman::XS qw(:constants); use Gearman::XS::Worker; $worker = new Gearman::XS::Worker; $ret = $worker->add_server($host, $port); if ($ret != GEARMAN_SUCCESS) { printf(STDERR "%s\n", $worker->error()); exit(1); } $ret = $worker->add_function("reverse", 0, \&reverse, $options); if ($ret != GEARMAN_SUCCESS) { printf(STDERR "%s\n", $worker->error()); } while (1) { my $ret = $worker->work(); if ($ret != GEARMAN_SUCCESS) { printf(STDERR "%s\n", $worker->error()); } } sub reverse { $job = shift; $workload = $job->workload(); $result = reverse($workload); printf("Job=%s Function_Name=%s Workload=%s Result=%s\n", $job->handle(), $job->function_name(), $job->workload(), $result); return $result; }
Gearman::XS::Worker is a worker class for the Gearman distributed job system using libgearman.
Returns a Gearman::XS::Worker object.
Add a job server to a worker. This goes into a list of servers than can be used to run tasks. No socket I/O happens here, it is just added to a list. Returns a standard gearman return value.
Add a list of job servers to a worker. The format for the server list is: SERVER[:PORT][,SERVER[:PORT]]... No socket I/O happens here, it is just added to a list. Returns a standard gearman return value.
Remove all servers currently associated with the worker.
Send data to all job servers to see if they echo it back. This is a test function to see if job servers are responding properly. Returns a standard gearman return value.
Register and add callback function for worker. Returns a standard gearman return value.
Wait for a job and call the appropriate callback function when it gets one. Returns a standard gearman return value.
Get a job from one of the job servers. Returns a standard gearman return value.
Return an error string for the last error encountered.
Get options for a worker.
Set options for a worker.
Add options for a worker.
Remove options for a worker.
Get current socket I/O activity timeout value. Returns Timeout in milliseconds to wait for I/O activity.
Set socket I/O activity timeout for connections in milliseconds.
Register function with job servers with an optional timeout. The timeout specifies how many seconds the server will wait before marking a job as failed. Returns a standard gearman return value.
Unregister function with job servers. Returns a standard gearman return value.
Unregister all functions with job servers. Returns a standard gearman return value.
See if a function exists in the server. Returns 1 if the function exists, empty string if not.
When in non-blocking I/O mode, wait for activity from one of the servers.
Set logging function.
Any in libgearman plus many others of my own.
Copyright (C) 2013 Data Differential, ala Brian Aker, http://datadifferential.com/ Copyright (C) 2009-2010 Dennis Schoen
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.9 or, at your option, any later version of Perl 5 you may have available.
This is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Brian Aker <brian@tangent.org>
To install Gearman::XS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Gearman::XS
CPAN shell
perl -MCPAN -e shell install Gearman::XS
For more information on module installation, please visit the detailed CPAN module installation guide.