feat: strengthen module contracts and shared WebUI runtime
This commit is contained in:
@@ -8,6 +8,12 @@ from govoplan_core.core.dataflows import (
|
||||
CAPABILITY_DATAFLOW_TRIGGER_DISPATCHER,
|
||||
DataflowTriggerDispatcher,
|
||||
)
|
||||
from govoplan_core.core.events import (
|
||||
CAPABILITY_PLATFORM_EVENT_OUTBOX,
|
||||
PlatformEvent,
|
||||
PlatformEventOutbox,
|
||||
publish_platform_event,
|
||||
)
|
||||
from govoplan_core.core.module_management import load_startup_enabled_modules, startup_candidate_module_ids
|
||||
from govoplan_core.core.modules import ModuleContext
|
||||
from govoplan_core.core.notifications import CAPABILITY_NOTIFICATIONS_DISPATCH, NotificationDispatchProvider
|
||||
@@ -34,6 +40,7 @@ celery.conf.update(
|
||||
"govoplan.notifications.deliver_pending": {"queue": "notifications"},
|
||||
"govoplan.calendar.dispatch_outbox": {"queue": "calendar"},
|
||||
"govoplan.dataflow.dispatch_triggers": {"queue": "dataflow"},
|
||||
"govoplan.events.dispatch_outbox": {"queue": "events"},
|
||||
},
|
||||
worker_prefetch_multiplier=1,
|
||||
task_acks_late=True,
|
||||
@@ -49,6 +56,11 @@ celery.conf.update(
|
||||
"schedule": 60.0,
|
||||
"args": (100,),
|
||||
},
|
||||
"platform-events-every-ten-seconds": {
|
||||
"task": "govoplan.events.dispatch_outbox",
|
||||
"schedule": 10.0,
|
||||
"args": (100,),
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -96,8 +108,10 @@ def _calendar_outbox() -> CalendarOutboxProvider | None:
|
||||
return capability
|
||||
|
||||
|
||||
def _dataflow_trigger_dispatcher() -> DataflowTriggerDispatcher | None:
|
||||
registry = _platform_registry()
|
||||
def _dataflow_trigger_dispatcher(
|
||||
registry: PlatformRegistry | None = None,
|
||||
) -> DataflowTriggerDispatcher | None:
|
||||
registry = registry or _platform_registry()
|
||||
if not registry.has_capability(CAPABILITY_DATAFLOW_TRIGGER_DISPATCHER):
|
||||
return None
|
||||
capability = registry.require_capability(
|
||||
@@ -108,6 +122,18 @@ def _dataflow_trigger_dispatcher() -> DataflowTriggerDispatcher | None:
|
||||
return capability
|
||||
|
||||
|
||||
def _platform_event_outbox(
|
||||
registry: PlatformRegistry | None = None,
|
||||
) -> PlatformEventOutbox | None:
|
||||
registry = registry or _platform_registry()
|
||||
if not registry.has_capability(CAPABILITY_PLATFORM_EVENT_OUTBOX):
|
||||
return None
|
||||
capability = registry.require_capability(CAPABILITY_PLATFORM_EVENT_OUTBOX)
|
||||
if not isinstance(capability, PlatformEventOutbox):
|
||||
raise RuntimeError("Platform event outbox capability is invalid")
|
||||
return capability
|
||||
|
||||
|
||||
@celery.task(name="govoplan.campaigns.send_email", bind=True, max_retries=0)
|
||||
def send_email(self, job_id: str):
|
||||
"""Send one explicitly queued campaign job.
|
||||
@@ -197,3 +223,39 @@ def dispatch_dataflow_triggers(self, limit: int = 100):
|
||||
result = dict(provider.dispatch_due(session, limit=limit))
|
||||
session.commit()
|
||||
return result
|
||||
|
||||
|
||||
@celery.task(
|
||||
name="govoplan.events.dispatch_outbox",
|
||||
bind=True,
|
||||
max_retries=0,
|
||||
)
|
||||
def dispatch_platform_events(self, limit: int = 100):
|
||||
"""Deliver committed platform events once across all worker processes."""
|
||||
|
||||
from govoplan_core.db.session import get_database
|
||||
|
||||
with get_database().SessionLocal() as session:
|
||||
registry = _platform_registry()
|
||||
outbox = _platform_event_outbox(registry)
|
||||
if outbox is None:
|
||||
return {"selected": 0, "dispatched": 0, "failed": 0}
|
||||
dataflow_dispatcher = _dataflow_trigger_dispatcher(registry)
|
||||
|
||||
def dispatch(event: PlatformEvent) -> None:
|
||||
if (
|
||||
dataflow_dispatcher is not None
|
||||
and event.classification in {"public", "internal"}
|
||||
):
|
||||
dataflow_dispatcher.ingest_event(session, event=event)
|
||||
publish_platform_event(event)
|
||||
|
||||
result = dict(
|
||||
outbox.dispatch_pending(
|
||||
session,
|
||||
dispatcher=dispatch,
|
||||
limit=limit,
|
||||
)
|
||||
)
|
||||
session.commit()
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user