allow for closing stuff in beacons

Like the filehandler for inotify
This commit is contained in:
Daniel Wallace 2016-10-05 15:42:33 -05:00
parent a23ce84e57
commit 727d4f309a
3 changed files with 18 additions and 1 deletions

View file

@ -101,6 +101,12 @@ which point the normal beacon interval will resume.
.. _beacon-example:
.. note::
For beacon writers: If you need extra stuff to happen, like closing file
handles for the ``disable_during_state_run`` to actually work, you can add
a `close()` function to the beacon to run those extra things. See the
`inotify` beacon.
Beacon Example
==============

View file

@ -86,7 +86,12 @@ class Beacon(object):
if re.match('state.*', job['fun']):
is_running = True
if is_running:
log.info('Skipping beacon {0}. State run in progress.'.format(mod))
close_str = '{0}.close'.format(mod)
if close_str in self.beacons:
log.info('Closing beacon {0}. State run in progress.'.format(mod))
self.beacons[close_str](b_config[mod])
else:
log.info('Skipping beacon {0}. State run in progress.'.format(mod))
continue
# Fire the beacon!
raw = self.beacons[fun_str](b_config[mod])

View file

@ -265,3 +265,9 @@ def beacon(config):
# Return event data
return ret
def close(config):
if 'inotify.notifier' in __context__:
__context__['inotify.notifier'].stop()
del __context__['inotify.notifier']