Skip to content

Commit

Permalink
Add logging to INT, TERM, and QUIT handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Oct 30, 2023
1 parent e2f6234 commit b6fdd78
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Revision history for Perl extension PGXN::Manager
0.31.2
- Combined the pgxn_consumer PID number and file location into one
output.
- Configured handlers for INT, TERM, and QUIT signals to log flagging
for shutdown in the next loop.

0.31.1 2023-10-07T21:40:53Z
- Restored the writing of the pgxn_consumer PID file, accidentally
Expand Down
10 changes: 9 additions & 1 deletion lib/PGXN/Manager/Consumer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@ sub go {
$cfg->{log_fh} = _log_fh delete $cfg->{'log-file'};
$cfg->{pid_file} = delete $cfg->{'pid-file'} if exists $cfg->{'pid-file'};
my $cmd = $class->new( $cfg );
$SIG{QUIT} = $SIG{INT} = $SIG{TERM} = sub { $cmd->continue(0) };
$SIG{$_} = $cmd->_signal_handler($_) for qw(TERM INT QUIT);
$cmd->run(@ARGV);
}

sub _signal_handler {
my ($self, $sig) = @_;
return sub {
$self->log("INFO: $sig signal caught; flagging shutdown for next loop");
$self->continue(0);
};
}

sub DEMOLISH {
my $self = shift;
if (my $path = $self->pid_file) {
Expand Down

0 comments on commit b6fdd78

Please sign in to comment.