Added support for ApplicationStartedEvent and ApplicationStoppedEvent
This commit is contained in:
parent
badb739a8c
commit
a4f075a4c1
2 changed files with 27 additions and 0 deletions
|
@ -19,6 +19,7 @@ from .context import register_backends
|
||||||
from .cron.scheduler import CronScheduler
|
from .cron.scheduler import CronScheduler
|
||||||
from .event.processor import EventProcessor
|
from .event.processor import EventProcessor
|
||||||
from .message.event import Event, StopEvent
|
from .message.event import Event, StopEvent
|
||||||
|
from .message.event.application import ApplicationStartedEvent, ApplicationStoppedEvent
|
||||||
from .message.request import Request
|
from .message.request import Request
|
||||||
from .message.response import Response
|
from .message.response import Response
|
||||||
|
|
||||||
|
@ -113,6 +114,7 @@ class Daemon:
|
||||||
|
|
||||||
def stop_app(self):
|
def stop_app(self):
|
||||||
""" Stops the backends and the bus """
|
""" Stops the backends and the bus """
|
||||||
|
self.bus.post(ApplicationStoppedEvent())
|
||||||
for backend in self.backends.values():
|
for backend in self.backends.values():
|
||||||
backend.stop()
|
backend.stop()
|
||||||
self.bus.stop()
|
self.bus.stop()
|
||||||
|
@ -133,6 +135,8 @@ class Daemon:
|
||||||
if Config.get_cronjobs():
|
if Config.get_cronjobs():
|
||||||
CronScheduler(jobs=Config.get_cronjobs()).start()
|
CronScheduler(jobs=Config.get_cronjobs()).start()
|
||||||
|
|
||||||
|
self.bus.post(ApplicationStartedEvent())
|
||||||
|
|
||||||
# Poll for messages on the bus
|
# Poll for messages on the bus
|
||||||
try:
|
try:
|
||||||
self.bus.poll()
|
self.bus.poll()
|
||||||
|
|
23
platypush/message/event/application.py
Normal file
23
platypush/message/event/application.py
Normal 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:
|
||||||
|
|
Loading…
Reference in a new issue