Skip to content

Commit

Permalink
change AnyEvent::Gearman to Gearman
Browse files Browse the repository at this point in the history
  • Loading branch information
khs committed May 29, 2012
1 parent 6a72a56 commit 7fedc02
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 247 deletions.
138 changes: 0 additions & 138 deletions Gearman-Manager/lib/Gearman/Manager/BaseWorker.pm

This file was deleted.

82 changes: 0 additions & 82 deletions Gearman-Manager/lib/Gearman/Manager/ProcManager.pm

This file was deleted.

26 changes: 19 additions & 7 deletions Gearman-Manager/lib/Gearman/SlotWorker.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package Gearman::SlotWorker;
use namespace::autoclean;
use Moose;
use Any::Moose;
use AnyEvent;
use EV;
use AnyEvent::Gearman;
use Gearman::Worker;
use IPC::AnyEvent::Gearman;

use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($DEBUG);

Expand Down Expand Up @@ -34,24 +35,35 @@ sub BUILD{
}
}
}

use Data::Dumper;
sub start{
my $class = shift;
my $worker = $class->new();

my $cv = AE::cv;

my $w = gearman_worker 'localhost:9999';
my $w = Gearman::Worker->new;
$w->job_servers('localhost:9999');

foreach my $m (@{$worker->exported}){
DEBUG "register ".$m->fully_qualified_name;
$w->register_function($m->fully_qualified_name=>
sub{my $job=shift;
return $m->execute($worker,$job);
my $fname = $m->fully_qualified_name;
my $fcode = $m->body;
$w->register_function($fname =>
sub{
DEBUG "WORKER ". $fname;
my $job = shift;
my $workload = $job->arg;
my $res = $fcode->($worker,$workload);
return $res;
});
}

my $ipcr = IPC::AnyEvent::Gearman->new(servers=>['localhost:9999']);
$ipcr->listen();

my $t = AE::timer 0, 0.1, sub{$w->work(stop_if=>sub{1});};

$cv->recv;
}
1;
13 changes: 9 additions & 4 deletions Gearman-Manager/lib/TestWorker.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package TestWorker;
use namespace::autoclean;
use Moose;
use Any::Moose;
extends 'Gearman::SlotWorker';
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($DEBUG);
Expand All @@ -10,16 +10,21 @@ sub BUILD{
};
sub workmethod{
my $self = shift;
DEBUG "workmethod:".$self;
my $data = shift;
DEBUG "workmethod:".$data;
return "HELLO";
}
sub dowork{
my $self = shift;
DEBUG "work:".$self;
my $data = shift;
DEBUG "work:".$data;
return "HELLO";
}

sub _private{
my $self = shift;
DEBUG "_private:".$self;
my $data = shift;
DEBUG "_private:".$data;
}

=pod
Expand Down
19 changes: 3 additions & 16 deletions Gearman-Manager/testClient.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,13 @@


my $client = Gearman::Client->new();
$client->job_servers('mabook.com:9998');
$client->job_servers('localhost:9999');

my %result;
my $taskset = $client->new_task_set;
for(1..5){
$taskset->add_task('TestWorker::echo', "PING",
{
on_complete => sub{
my $resstr = ${$_[0]};
print "ECHO: ";
print ($resstr);
print "\n";
}
}
);
}
$taskset->wait;
my $taskset = $client->new_task_set;
for(1..5){
$taskset->add_task('TestWorkerAny::echo', "PING",
print "WORK $1\n";
$taskset->add_task('TestWorker::dowork', "PING",
{
on_complete => sub{
my $resstr = ${$_[0]};
Expand Down

0 comments on commit 7fedc02

Please sign in to comment.