diff options
| author | franck cuny <franck@lumberjaph.net> | 2010-06-09 18:19:38 +0200 |
|---|---|---|
| committer | franck cuny <franck@lumberjaph.net> | 2010-06-09 18:19:38 +0200 |
| commit | 5b2042053577cc6381c40c4fb5d5264e79a0312d (patch) | |
| tree | 643da7415c478ee5e444231690fe8cd91329b75c /lib/presque/worker/Role/Management.pm | |
| parent | a simple worker; a role for the REST interface to presque; reg signals (diff) | |
| download | presque-worker-5b2042053577cc6381c40c4fb5d5264e79a0312d.tar.gz | |
add logger; move some code for work and job in roles;
Diffstat (limited to 'lib/presque/worker/Role/Management.pm')
| -rw-r--r-- | lib/presque/worker/Role/Management.pm | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/lib/presque/worker/Role/Management.pm b/lib/presque/worker/Role/Management.pm index cdfcd6d..cceea4e 100644 --- a/lib/presque/worker/Role/Management.pm +++ b/lib/presque/worker/Role/Management.pm @@ -7,47 +7,31 @@ has shut_down => (is => 'rw', isa => 'Bool', default => 0,); before start => sub { my $self = shift; $self->rest_register_worker; + $SIG{INT} = sub { $self->_shutdown }; + $SIG{TERM} = sub { $self->_shutdown }; + $SIG{QUIT} = sub { $self->_graceful_shutdown }; + $SIG{USR1} = sub { $self->_kill_child }; + $SIG{CHLD} = 'IGNORE'; }; -after start => sub { - my $self = shift; - $self->rest_unregister_worker; -}; - -before start => sub { - my $self = shift; - $SIG{'INT'} = sub { $self->_shutdown }; - $SIG{'TERM'} = sub { $self->_shutdown }; - $SIG{'QUIT'} = sub { $self->_graceful_shutdown }; - $SIG{'USR1'} = sub { $self->_kill_child }; -}; +after start => sub { (shift)->rest_unregister_worker; }; +after _graceful_shutdown => sub { (shift)->rest_unregister_worker; }; +after _shutdown => sub { (shift)->rest_unregister_worker; }; sub _shutdown { my $self = shift; - $self->logger->log( - level => 'info', - message => 'worker ' . $self->worker_id . ' shuting down' - ); $self->shut_down(1); $self->_kill_child(); } sub _graceful_shutdown { my $self = shift; - $self->logger->log( - level => 'info', - message => 'worker ' . $self->worker_id . ' kill child' - ); $self->shut_down(1); $self->_kill_child(); } sub _kill_child { my $self = shift; - $self->logger->log( - level => 'info', - message => 'worker ' . $self->worker_id . ' shuting down gracefuly' - ); } 1; |
