Fix long-polling request for project notifications.

This commit is contained in:
grossmj committed 2019-02-23 21:08:52 +07:00
1 parent 10702f87bc
commit 7fe8f7e716
10 files changed
+82 -64

No files matched your search

+17 -7
View File
@@ -122,6 +122,16 @@ class Project:
assert self._status != "closed"
self.dump()
def emit_notification(self, action, event):
"""
Emit a notification to all clients using this project.
:param action: Action name
:param event: Event to send
"""
self.controller.notification.project_emit(action, event, project_id=self.id)
async def update(self, **kwargs):
"""
Update the project
@@ -135,7 +145,7 @@ class Project:
# We send notif only if object has changed
if old_json != self.__json__():
self.controller.notification.project_emit("project.updated", self.__json__())
self.emit_notification("project.updated", self.__json__())
self.dump()
# update on computes
@@ -533,7 +543,7 @@ class Project:
self._project_created_on_compute.add(compute)
await node.create()
self._nodes[node.id] = node
self.controller.notification.project_emit("node.created", node.__json__())
self.emit_notification("node.created", node.__json__())
if dump:
self.dump()
return node
@@ -558,7 +568,7 @@ class Project:
del self._nodes[node.id]
await node.destroy()
self.dump()
self.controller.notification.project_emit("node.deleted", node.__json__())
self.emit_notification("node.deleted", node.__json__())
@open_required
def get_node(self, node_id):
@@ -623,7 +633,7 @@ class Project:
if drawing_id not in self._drawings:
drawing = Drawing(self, drawing_id=drawing_id, **kwargs)
self._drawings[drawing.id] = drawing
self.controller.notification.project_emit("drawing.created", drawing.__json__())
self.emit_notification("drawing.created", drawing.__json__())
if dump:
self.dump()
return drawing
@@ -644,7 +654,7 @@ class Project:
drawing = self.get_drawing(drawing_id)
del self._drawings[drawing.id]
self.dump()
self.controller.notification.project_emit("drawing.deleted", drawing.__json__())
self.emit_notification("drawing.deleted", drawing.__json__())
@open_required
async def add_link(self, link_id=None, dump=True):
@@ -671,7 +681,7 @@ class Project:
if force_delete is False:
raise
self.dump()
self.controller.notification.project_emit("link.deleted", link.__json__())
self.emit_notification("link.deleted", link.__json__())
@open_required
def get_link(self, link_id):
@@ -743,7 +753,7 @@ class Project:
self._clean_pictures()
self._status = "closed"
if not ignore_notification:
self.controller.notification.project_emit("project.closed", self.__json__())
self.emit_notification("project.closed", self.__json__())
self.reset()
def _clean_pictures(self):