Skip to content

Commit

Permalink
postpone service notifications per default
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan committed Mar 16, 2014
1 parent d8c181c commit f0e224d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
9 changes: 5 additions & 4 deletions lib/Rex/Commands/Service.pm
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ sub service {

my $notify = Rex::get_current_connection()->{notify};
$notify->add(
type => "service",
name => $service,
options => {},
cb => sub {
type => "service",
name => $service,
postpone => 1,
options => {},
cb => sub {
my ($option) = shift;
Rex::Logger::debug("Restarting notified service: $service");
service( $service => "restart" );
Expand Down
19 changes: 13 additions & 6 deletions lib/Rex/Notify.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@ sub new {
sub add {
my ( $self, %option ) = @_;

return if ($self->{__in_notify__});
return if ( $self->{__in_notify__} );

if ( exists $self->{__types__}->{ $option{type} }->{ $option{name} } ) {
die( "A resource of the type $option{type} and name $option{name}"
. "already exists." );
Rex::Logger::debug(
"A resource of the type $option{type} and name $option{name}"
. "already exists.",
"warn"
);
return;
}

$self->{__types__}->{ $option{type} }->{ $option{name} } = {
options => $option{options},
cb => $option{cb},
postpone => $option{postpone} || 0,
options => $option{options},
cb => $option{cb},
};
}

Expand All @@ -47,7 +52,9 @@ sub run {

if ( exists $self->{__types__}->{ $option{type} }
&& exists $self->{__types__}->{ $option{type} }->{ $option{name} }
&& exists $self->{__types__}->{ $option{type} }->{ $option{name} }->{cb} )
&& exists $self->{__types__}->{ $option{type} }->{ $option{name} }->{cb}
&& $self->{__types__}->{ $option{type} }->{ $option{name} }->{postpone} ==
0 )
{
Rex::Logger::debug("Running notify $option{type} -> $option{name}");

Expand Down

0 comments on commit f0e224d

Please sign in to comment.