rapid interations of server side app and firefox extension
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""Cross-process event publishing via Redis.
|
||||
|
||||
This module provides synchronous event publishing for use in Celery tasks.
|
||||
The events are consumed by the WebSocket module which broadcasts them to clients.
|
||||
"""
|
||||
|
||||
import json
|
||||
import redis
|
||||
|
||||
from app.config import get_settings
|
||||
|
||||
# Redis pub/sub channel for cross-process events
|
||||
EVENTS_CHANNEL = "gallery_subscriber:events"
|
||||
|
||||
|
||||
def publish_event(event_type: str, data: dict):
|
||||
"""Publish an event to Redis (for use in Celery tasks).
|
||||
|
||||
This is a sync function that can be called from Celery tasks.
|
||||
The Quart app subscribes to these events and broadcasts to WebSocket clients.
|
||||
|
||||
Args:
|
||||
event_type: Type of event (e.g., "download.started", "download.completed")
|
||||
data: Event payload data
|
||||
"""
|
||||
settings = get_settings()
|
||||
r = redis.from_url(settings.redis_url)
|
||||
message = json.dumps({"type": event_type, "data": data})
|
||||
r.publish(EVENTS_CHANNEL, message)
|
||||
r.close()
|
||||
Reference in New Issue
Block a user