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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.