Hi,
1 -- on twp distinct shells: gearman -w -f test sleep 1
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:
and here the output with 2 workers which just sleep for 1 second and respond with an empty string1: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.");
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.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.
Also you can use a completely OO Job object:
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?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.");
1 -- on twp distinct shells: gearman -w -f test sleep 1
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Another Gearman perl module?
by ikegami (Patriarch) on Nov 16, 2009 at 21:12 UTC | |
by oha (Friar) on Nov 16, 2009 at 21:17 UTC | |
by ikegami (Patriarch) on Nov 16, 2009 at 21:30 UTC | |
by oha (Friar) on Nov 17, 2009 at 14:31 UTC | |
by ikegami (Patriarch) on Nov 18, 2009 at 00:16 UTC | |
Re: Another Gearman perl module?
by Mr. Muskrat (Canon) on Nov 17, 2009 at 23:32 UTC | |
Re: Another Gearman perl module?
by ikegami (Patriarch) on Nov 16, 2009 at 21:13 UTC | |
Re: Another Gearman perl module?
by runrig (Abbot) on Apr 05, 2010 at 21:35 UTC |
Back to
Meditations