diff options
author | Oliver Poignant <oliver@poignant.se> | 2017-01-04 15:18:14 +0100 |
---|---|---|
committer | Oliver Poignant <oliver@poignant.se> | 2017-01-04 15:18:14 +0100 |
commit | 3b45ec948debb098ed7b7d3a1775b5e42a41be43 (patch) | |
tree | 4983a0f05598990212ca94a6c37f0e52cfd1315e /gitautodeploy/events.py | |
parent | c81d62005871d006c4d1feb0c27c15a469f60a35 (diff) | |
download | Git-Auto-Deploy-3b45ec948debb098ed7b7d3a1775b5e42a41be43.zip Git-Auto-Deploy-3b45ec948debb098ed7b7d3a1775b5e42a41be43.tar.gz Git-Auto-Deploy-3b45ec948debb098ed7b7d3a1775b5e42a41be43.tar.bz2 |
Support for browser notifications
Diffstat (limited to 'gitautodeploy/events.py')
-rw-r--r-- | gitautodeploy/events.py | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/gitautodeploy/events.py b/gitautodeploy/events.py index 8bbaaa1..5e177a0 100644 --- a/gitautodeploy/events.py +++ b/gitautodeploy/events.py @@ -33,10 +33,7 @@ class SystemEvent(object): def register_message(self, message, level="INFO"): self.messages.append(message) - self.hub.update_action(self, message) - - def notify(self): - self.hub.notify(self) + self.hub.notify_observers(type="event-updated", event=self.dict_repr()) def set_id(self, id): self.id = id @@ -46,9 +43,12 @@ class SystemEvent(object): def set_waiting(self, value): self.waiting = value + self.hub.notify_observers(type="event-updated", event=self.dict_repr()) def set_success(self, value): self.success = value + self.hub.notify_observers(type="event-updated", event=self.dict_repr()) + self.hub.notify_observers(type="event-success", id=self.id, success=value) def log_debug(self, message): self.logger.debug(message) @@ -70,8 +70,8 @@ class SystemEvent(object): self.logger.critical(message) self.register_message(message, "CRITICAL") - def update(self): - self.hub.update_action(self) + #def update(self): + # self.hub.notify_observers(type="event-updated", event=self.dict_repr()) class WebhookAction(SystemEvent): @@ -119,6 +119,19 @@ class StartupEvent(SystemEvent): data['ws-started'] = self.ws_started return data + def set_http_started(self, value): + self.http_started = value + self.hub.notify_observers(type="event-updated", event=self.dict_repr()) + self.validate_success() + + def set_ws_started(self, value): + self.ws_started = value + self.hub.notify_observers(type="event-updated", event=self.dict_repr()) + self.validate_success() + + def validate_success(self): + if self.http_started and self.ws_started: + self.set_success(True) class EventStore(object): @@ -134,7 +147,7 @@ class EventStore(object): if observer in self.observers: self.observers.remove(observer) - def update_observers(self, *args, **kwargs): + def notify_observers(self, *args, **kwargs): for observer in self.observers: observer.update(*args, **kwargs) @@ -143,18 +156,12 @@ class EventStore(object): event.register_hub(self) self.next_id = self.next_id + 1 self.actions.append(event) - self.update_observers(event=event) + self.notify_observers(type="new-event", event=event.dict_repr()) # Store max 100 actions if len(self.actions) > 100: self.actions.pop(0) - def notify(self, event): - self.update_observers(event=event) - - def update_action(self, event, message=None): - self.update_observers(event=event, message=message) - def dict_repr(self): action_repr = [] for action in self.actions: |