A notification stream with process monitoring

This commit is contained in:
Julien Duponchelle
2015-03-04 16:01:56 +01:00
parent 57f5e7a7d9
commit e9ec5c8a37
15 changed files with 256 additions and 25 deletions

View File

@ -65,6 +65,9 @@ class Project:
self._used_tcp_ports = set()
self._used_udp_ports = set()
# List of clients listen for notifications
self._listeners = set()
if path is None:
path = os.path.join(self._location, self._id)
try:
@ -416,3 +419,26 @@ class Project:
# We import it at the last time to avoid circular dependencies
from ..modules import MODULES
return MODULES
def emit(self, action, event):
"""
Send an event to all the client listens for notifications
:param action: Action happened
:param event: Event sended to the client
"""
for listener in self._listeners:
listener.put_nowait((action, event, ))
def get_listen_queue(self):
"""Get a queue where you receive all the events related to the
project."""
queue = asyncio.Queue()
self._listeners.add(queue)
return queue
def stop_listen_queue(self, queue):
"""Stop sending notification to this clients"""
self._listeners.remove(queue)