Consolidate handler tracking (#49338)

* Consolidate handler tracking
  -  Remove unused code. ci_complete
  - unit test fixes. ci_complete
  - Restore previous behavior of matching a single handler
  - when notifying a host for a handler, return True if it was added, False otherwise, to reduce copied logic
  - rename funcitons for clarity. ci_complete
  - Remove handler logic for static includes which was disabled previously
This commit is contained in:
Matt Martz 2018-12-11 09:58:19 -06:00 committed by Brian Coca
parent 62b2a08cfb
commit 2a469fd959
7 changed files with 41 additions and 133 deletions

View file

@ -25,10 +25,12 @@ from ansible.playbook.task import Task
class Handler(Task):
_listen = FieldAttribute(isa='list')
_listen = FieldAttribute(isa='list', default=list)
def __init__(self, block=None, role=None, task_include=None):
self._flagged_hosts = []
self.notified_hosts = []
self.cached_name = False
super(Handler, self).__init__(block=block, role=role, task_include=task_include)
@ -41,13 +43,14 @@ class Handler(Task):
t = Handler(block=block, role=role, task_include=task_include)
return t.load_data(data, variable_manager=variable_manager, loader=loader)
def flag_for_host(self, host):
# assert instanceof(host, Host)
if host not in self._flagged_hosts:
self._flagged_hosts.append(host)
def notify_host(self, host):
if not self.is_host_notified(host):
self.notified_hosts.append(host)
return True
return False
def has_triggered(self, host):
return host in self._flagged_hosts
def is_host_notified(self, host):
return host in self.notified_hosts
def serialize(self):
result = super(Handler, self).serialize()