[core] Added ApplicationStartedEvent to Redis bus instead of application.

The Redis bus now uses a pub/sub architecture rather than a simple
queue.

Earlier on, the application could post an event to the queue and then
pick it up when it started listening.

When doing a publish on a pub/sub channel, however, any messages
sent before the client started listening will be lost.
This commit is contained in:
Fabio Manganiello 2024-07-16 20:56:51 +02:00
parent 837b0fad98
commit dc96b4995c
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 4 additions and 2 deletions

View file

@ -19,7 +19,6 @@ from platypush.entities import init_entities_engine, EntitiesEngine
from platypush.event.processor import EventProcessor
from platypush.logger import Logger
from platypush.message.event import Event
from platypush.message.event.application import ApplicationStartedEvent
from platypush.message.request import Request
from platypush.message.response import Response
from platypush.utils import get_enabled_plugins, get_redis_conf
@ -462,7 +461,6 @@ class Application:
self.cron_scheduler.start()
assert self.bus, 'The bus is not running'
self.bus.post(ApplicationStartedEvent())
# Poll for messages on the bus
try:

View file

@ -37,8 +37,12 @@ class RedisBus(Bus):
"""
Polls the Redis queue for new messages
"""
from platypush.message.event.application import ApplicationStartedEvent
with self.pubsub as pubsub:
pubsub.subscribe(self.redis_queue)
self.post(ApplicationStartedEvent())
try:
for msg in pubsub.listen():
if msg.get('type') != 'message':