Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi,

i was trying http://gearman.org and i've therefor got from cpan Gearman::Client and Gearman::Client::Async but, for what i need, i felt like they weren't designed as i need, and i've tried to write another which suits best my needs.

Having not wrote any documentation, i'll just show you the usage:

use Gearman::OO::Client; my $client = Gearman::OO::Client->new( servers => ['127.0.0.1:4730'], max_queue => 4, ); logit("connected"); foreach my $id (1..8) { $client->submit( func=>'test', req=>"Data for $id", complete => sub { logit("completed #$id: @_"); }, error => sub { logit("ERROR #$id! @_"); }, ); logit("added #$id"); } logit("sync..."); $client->sync(); logit("done.");

and here the output with 2 workers which just sleep for 1 second and respond with an empty string1:

00:00:00 connected 00:00:00 added #1 00:00:00 added #2 00:00:00 added #3 00:00:00 added #4 00:00:01 completed #1: 00:00:01 completed #2: 00:00:01 added #5 00:00:01 added #6 00:00:02 completed #3: 00:00:02 completed #4: 00:00:02 added #7 00:00:02 added #8 00:00:02 sync... 00:00:03 completed #5: 00:00:03 completed #6: 00:00:04 completed #7: 00:00:04 completed #8: 00:00:04 done.

As you can see, some jobs are added early up to the max_queue limit, then it will block until any of the previous job complete to continue.

Also you can use a completely OO Job object:

package MyJob; use base 'Gearman::OO::Job'; sub new { my ($class, %args) = @_; bless \%args, $class; } sub function { 'test'; } sub complete { my ($self, $data) = @_; logit("$self completed($data)") +; } sub req_data { my ($self) = @_; return $self->{req}; } use Gearman::OO::Client; my $client = Gearman::OO::Client->new( servers => ['127.0.0.1:4730'], max_queue => 4, ); logit("connected"); foreach my $id (1..8) { $client->submit_job(MyJob->new(req => "OO #$id")); logit("added #$id"); } logit("sync..."); $client->sync(); logit("done.");

and now the meditation: anyone think this could be usefull? and if so, which name should i use? does it merit to be on CPAN?


1 -- on twp distinct shells: gearman -w -f test sleep 1

In reply to Another Gearman perl module? by oha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2022-05-24 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?