Skip to content

Commit

Permalink
v0.001
Browse files Browse the repository at this point in the history
  • Loading branch information
sng2c committed Jun 7, 2012
1 parent ef3a098 commit 0869a86
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 19 deletions.
8 changes: 3 additions & 5 deletions lib/Gearman/Slot.pm
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ){
Expand All @@ -70,6 +67,7 @@ sub start{
$self->worker_watcher(undef);
}
});
$self->is_stopped(0);
weaken($self);
}
else{
Expand Down Expand Up @@ -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;
}
}

Expand Down
11 changes: 11 additions & 0 deletions lib/Gearman/SlotManager.pm
Expand Up @@ -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
7 changes: 3 additions & 4 deletions lib/Gearman/SlotWorker.pm
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions t/01-SlotWorkerOverwork.t
Expand Up @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions t/03-SlotOverwork.t
Expand Up @@ -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;
Expand Down Expand Up @@ -50,7 +50,6 @@ my $res = $cv->recv;
isnt $res,'timeout','ends successfully';
$slot->stop();
undef($t);
undef($w);
undef($c);
undef($slot);
gstop();
Expand Down
2 changes: 1 addition & 1 deletion t/05-SlotManagerWork.t
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions t/testClient.pl
Expand Up @@ -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]};
Expand Down
6 changes: 3 additions & 3 deletions testManager.pl
Expand Up @@ -31,9 +31,9 @@ package main;
},
slots=>{
'TestWorker'=>{
min=>1,
max=>10,
workleft=>10,
min=>20,
max=>50,
workleft=>0,
}
}
}
Expand Down

0 comments on commit 0869a86

Please sign in to comment.