Skip to content

Commit

Permalink
when notifying a host for a handler, return True if it was added, Fal…
Browse files Browse the repository at this point in the history
…se otherwise, to reduce copied logic
  • Loading branch information
sivel committed Dec 3, 2018
1 parent 551895a commit 4751500
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/ansible/playbook/handler.py
Expand Up @@ -43,9 +43,11 @@ def load(data, block=None, role=None, task_include=None, variable_manager=None,
t = Handler(block=block, role=role, task_include=task_include)
return t.load_data(data, variable_manager=variable_manager, loader=loader)

def do_notify(self, host):
if host not in self.notified_hosts:
def notify_host(self, host):
if not self.is_notified(host):
self.notified_hosts.append(host)
return True
return False

def is_notified(self, host):
return host in self.notified_hosts
Expand Down
9 changes: 3 additions & 6 deletions lib/ansible/plugins/strategy/__init__.py
Expand Up @@ -540,8 +540,7 @@ def parent_handler_match(target_handler, handler_name):
target_handler = search_handler_blocks_by_name(handler_name, iterator._play.handlers)
if target_handler is not None:
found = True
if not target_handler.is_notified(original_host):
target_handler.do_notify(original_host)
if target_handler.notify_host(original_host):
self._tqm.send_callback('v2_playbook_on_notify', target_handler, original_host)
else:
# As there may be more than one handler with the notified name as the
Expand All @@ -550,8 +549,7 @@ def parent_handler_match(target_handler, handler_name):
for target_handler in target_handler_block.block:
if parent_handler_match(target_handler, handler_name):
found = True
if not target_handler.is_notified(original_host):
target_handler.do_notify(original_host)
if target_handler.notify_host(original_host):
self._tqm.send_callback('v2_playbook_on_notify', target_handler, original_host)
break
if found:
Expand All @@ -565,8 +563,7 @@ def parent_handler_match(target_handler, handler_name):
else:
found = True

if not listening_handler.is_notified(original_host):
listening_handler.do_notify(original_host)
if listening_handler.notify_host(original_host):
self._tqm.send_callback('v2_playbook_on_notify', listening_handler, original_host)

# and if none were found, then we raise an error
Expand Down

0 comments on commit 4751500

Please sign in to comment.