Added support for ApplicationStartedEvent and ApplicationStoppedEvent

This commit is contained in:
Fabio Manganiello 2018-09-24 09:18:46 +00:00
parent badb739a8c
commit a4f075a4c1
2 changed files with 27 additions and 0 deletions

View file

@ -19,6 +19,7 @@ from .context import register_backends
from .cron.scheduler import CronScheduler
from .event.processor import EventProcessor
from .message.event import Event, StopEvent
from .message.event.application import ApplicationStartedEvent, ApplicationStoppedEvent
from .message.request import Request
from .message.response import Response
@ -113,6 +114,7 @@ class Daemon:
def stop_app(self):
""" Stops the backends and the bus """
self.bus.post(ApplicationStoppedEvent())
for backend in self.backends.values():
backend.stop()
self.bus.stop()
@ -133,6 +135,8 @@ class Daemon:
if Config.get_cronjobs():
CronScheduler(jobs=Config.get_cronjobs()).start()
self.bus.post(ApplicationStartedEvent())
# Poll for messages on the bus
try:
self.bus.poll()

View file

@ -0,0 +1,23 @@
from platypush.message.event import Event
class ApplicationStartedEvent(Event):
"""
Event triggered when the application has started and all the backends have been registered
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class ApplicationStoppedEvent(Event):
"""
Event triggered when the application stops
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# vim:sw=4:ts=4:et: