diff --git a/lib/Gearman/Slot.pm b/lib/Gearman/Slot.pm index 3cb1b76..52d6b72 100644 --- a/lib/Gearman/Slot.pm +++ b/lib/Gearman/Slot.pm @@ -11,9 +11,7 @@ use Any::Moose; use AnyEvent; use Gearman::SlotWorker; use Scalar::Util qw(weaken); -use UUID::Random; use Data::Dumper; -use POSIX; has libs=>(is=>'rw',isa=>'ArrayRef',default=>sub{[]}); has job_servers=>(is=>'rw',isa=>'ArrayRef',required=>1); @@ -47,13 +45,12 @@ sub stop{ my $self = shift; $self->is_stopped(1); if( $self->worker_pid ){ - kill SIGINT, $self->worker_pid; + kill 2, $self->worker_pid; } } sub start{ my $self = shift; - $self->is_stopped(0); my $cpid = fork(); if( $cpid ){ @@ -70,6 +67,7 @@ sub start{ $self->worker_watcher(undef); } }); + $self->is_stopped(0); weaken($self); } else{ @@ -97,7 +95,7 @@ sub DEMOLISH{ my $self = shift; if( $self->worker_pid ){ DEBUG 'killed child forcely'; - kill SIGKILL, $self->worker_pid; + kill 9, $self->worker_pid; } } diff --git a/lib/Gearman/SlotManager.pm b/lib/Gearman/SlotManager.pm index a7ddd17..da84bf6 100644 --- a/lib/Gearman/SlotManager.pm +++ b/lib/Gearman/SlotManager.pm @@ -157,3 +157,14 @@ sub DEMOLISH{ __PACKAGE__->meta->make_immutable; 1; +__END__ + +=pod + +=head1 SYNOPSIS + +Will be updated soon. + +See testManager.pl in Gearman::SlotManager directory. + +=cut diff --git a/lib/Gearman/SlotWorker.pm b/lib/Gearman/SlotWorker.pm index f43c31e..a847691 100644 --- a/lib/Gearman/SlotWorker.pm +++ b/lib/Gearman/SlotWorker.pm @@ -6,8 +6,7 @@ package Gearman::SlotWorker; use Devel::GlobalDestruction; use namespace::autoclean; use Log::Log4perl qw(:easy); -Log::Log4perl->easy_init($DEBUG); -#Log::Log4perl->easy_init($ERROR); +Log::Log4perl->easy_init($ERROR); use Any::Moose; use AnyEvent; @@ -16,7 +15,7 @@ use AnyEvent::Gearman; use AnyEvent::Gearman::Worker::RetryConnection; use Scalar::Util qw(weaken); use LWP::Simple; -use POSIX; + # options has job_servers=>(is=>'rw',isa=>'ArrayRef', required=>1); has cv=>(is=>'rw',required=>1); @@ -65,7 +64,7 @@ sub BUILD{ $self->register(); - my $sigw = AE::signal SIGINT,sub{ + my $sigw = AE::signal 'INT',sub{ $self->is_stopped(1); if( !$self->is_busy ){ DEBUG 'SIGINT STOP'; diff --git a/t/01-SlotWorkerOverwork.t b/t/01-SlotWorkerOverwork.t index c1ec7a0..7ec5d32 100644 --- a/t/01-SlotWorkerOverwork.t +++ b/t/01-SlotWorkerOverwork.t @@ -6,9 +6,9 @@ use Gear; use AnyEvent; use AnyEvent::Gearman; use TestWorker; -# + use Log::Log4perl qw(:easy); -Log::Log4perl->easy_init($DEBUG); +Log::Log4perl->easy_init($ERROR); my $port = '9955'; my @js = ("localhost:$port"); diff --git a/t/03-SlotOverwork.t b/t/03-SlotOverwork.t index a912e53..cc6d8d3 100644 --- a/t/03-SlotOverwork.t +++ b/t/03-SlotOverwork.t @@ -8,7 +8,7 @@ use AnyEvent::Gearman; use Gearman::Slot; use Scalar::Util qw(weaken); use Log::Log4perl qw(:easy); -Log::Log4perl->easy_init($DEBUG); +Log::Log4perl->easy_init($ERROR); my $port = '9955'; my @js = ("localhost:$port"); my $cv = AE::cv; @@ -50,7 +50,6 @@ my $res = $cv->recv; isnt $res,'timeout','ends successfully'; $slot->stop(); undef($t); -undef($w); undef($c); undef($slot); gstop(); diff --git a/t/05-SlotManagerWork.t b/t/05-SlotManagerWork.t index 1aea2c0..fb4bb8d 100644 --- a/t/05-SlotManagerWork.t +++ b/t/05-SlotManagerWork.t @@ -7,7 +7,7 @@ use AnyEvent; use AnyEvent::Gearman; use Gearman::SlotManager; use Log::Log4perl qw(:easy); -Log::Log4perl->easy_init($DEBUG); +Log::Log4perl->easy_init($ERROR); use Scalar::Util qw(weaken); my $port = '9955'; diff --git a/t/testClient.pl b/t/testClient.pl index cb4950d..49347c4 100644 --- a/t/testClient.pl +++ b/t/testClient.pl @@ -10,9 +10,9 @@ my %result; my $taskset = $client->new_task_set; -for(1..1000){ +for(1..100){ my $n = $_; - $taskset->add_task('TestWorker::reverse', "PING", + $taskset->add_task('TestWorker::slowreverse', "PING", { on_complete => sub{ my $resstr = ${$_[0]}; diff --git a/testManager.pl b/testManager.pl index 401456f..0f33610 100644 --- a/testManager.pl +++ b/testManager.pl @@ -31,9 +31,9 @@ package main; }, slots=>{ 'TestWorker'=>{ - min=>1, - max=>10, - workleft=>10, + min=>20, + max=>50, + workleft=>0, } } }