With this new setup of everything firing events, this seemed like a good time to tackle this infinite recursion from the reactor. What this does is pass a "user" (Reactor) to all jobs that the reactor starts. Then the reactor skips all events created by that username-- thereby only reacting to events not caused by itself.
This commit is contained in:
Thomas Jackson 2014-12-24 14:37:02 -08:00
parent 1843eb0ba6
commit 30c3e57957

View File

@ -130,6 +130,9 @@ class Reactor(multiprocessing.Process, salt.state.Compiler):
self.wrap = ReactWrap(self.opts)
for data in self.event.iter_events(full=True):
# skip all events fired by ourselves
if data['data'].get('user') == self.wrap.event_user:
continue
reactors = self.list_reactors(data['tag'])
if not reactors:
continue
@ -147,6 +150,7 @@ class ReactWrap(object):
'''
# class-wide cache of clients
client_cache = None
event_user = 'Reactor'
def __init__(self, opts):
self.opts = opts
@ -166,7 +170,13 @@ class ReactWrap(object):
l_fun = getattr(self, low['state'])
try:
f_call = salt.utils.format_call(l_fun, low)
l_fun(*f_call.get('args', ()), **f_call.get('kwargs', {}))
kwargs = f_call.get('kwargs', {})
# TODO: pick one...
kwargs['__user__'] = self.event_user
kwargs['user'] = self.event_user
l_fun(*f_call.get('args', ()), **kwargs)
except Exception:
log.error(
'Failed to execute {0}: {1}\n'.format(low['state'], l_fun),