blob: cdfcd6da0fc14f71dda5cb82629fc4c4055ab98f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
package presque::worker::Role::Management;
use Moose::Role;
has shut_down => (is => 'rw', isa => 'Bool', default => 0,);
before start => sub {
my $self = shift;
$self->rest_register_worker;
};
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 };
};
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;
|