summary refs log tree commit diff
path: root/lib/presque/worker/Role/Management.pm
blob: cceea4e16130fc83e68e86e846d6dd2f0844a42f (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
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;
    $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 { (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->shut_down(1);
    $self->_kill_child();
}

sub _graceful_shutdown {
    my $self = shift;
    $self->shut_down(1);
    $self->_kill_child();
}

sub _kill_child {
    my $self = shift;
}

1;