feat(core): reconcile durable workflow instances
This commit is contained in:
@@ -22,6 +22,10 @@ from govoplan_core.core.events import (
|
||||
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
|
||||
from govoplan_core.core.workflows import (
|
||||
CAPABILITY_WORKFLOW_RUNTIME_WORKER,
|
||||
WorkflowRuntimeWorker,
|
||||
)
|
||||
from govoplan_core.core.registry import PlatformRegistry
|
||||
from govoplan_core.core.runtime import configure_runtime
|
||||
from govoplan_core.settings import settings
|
||||
@@ -47,6 +51,7 @@ celery.conf.update(
|
||||
"govoplan.dataflow.dispatch_runs": {"queue": "dataflow"},
|
||||
"govoplan.dataflow.purge_runs": {"queue": "dataflow"},
|
||||
"govoplan.dataflow.dispatch_triggers": {"queue": "dataflow"},
|
||||
"govoplan.workflow.reconcile": {"queue": "workflow"},
|
||||
"govoplan.events.dispatch_outbox": {"queue": "events"},
|
||||
"govoplan.events.purge_outbox": {"queue": "events"},
|
||||
},
|
||||
@@ -74,6 +79,11 @@ celery.conf.update(
|
||||
"schedule": 24 * 60 * 60.0,
|
||||
"args": (500,),
|
||||
},
|
||||
"workflow-reconcile-every-five-seconds": {
|
||||
"task": "govoplan.workflow.reconcile",
|
||||
"schedule": 5.0,
|
||||
"args": (50,),
|
||||
},
|
||||
"platform-events-every-ten-seconds": {
|
||||
"task": "govoplan.events.dispatch_outbox",
|
||||
"schedule": 10.0,
|
||||
@@ -157,6 +167,20 @@ def _dataflow_run_worker(
|
||||
return capability
|
||||
|
||||
|
||||
def _workflow_runtime_worker(
|
||||
registry: PlatformRegistry | None = None,
|
||||
) -> WorkflowRuntimeWorker | None:
|
||||
registry = registry or _platform_registry()
|
||||
if not registry.has_capability(CAPABILITY_WORKFLOW_RUNTIME_WORKER):
|
||||
return None
|
||||
capability = registry.require_capability(
|
||||
CAPABILITY_WORKFLOW_RUNTIME_WORKER
|
||||
)
|
||||
if not isinstance(capability, WorkflowRuntimeWorker):
|
||||
raise RuntimeError("Workflow runtime worker capability is invalid")
|
||||
return capability
|
||||
|
||||
|
||||
def _platform_event_outbox(
|
||||
registry: PlatformRegistry | None = None,
|
||||
) -> PlatformEventOutbox | None:
|
||||
@@ -310,6 +334,30 @@ def purge_dataflow_runs(self, limit: int = 500):
|
||||
return result
|
||||
|
||||
|
||||
@celery.task(
|
||||
name="govoplan.workflow.reconcile",
|
||||
bind=True,
|
||||
max_retries=0,
|
||||
)
|
||||
def reconcile_workflow_instances(self, limit: int = 50):
|
||||
"""Resume asynchronous Workflow steps from durable provider state."""
|
||||
|
||||
from govoplan_core.db.session import get_database
|
||||
|
||||
with get_database().SessionLocal() as session:
|
||||
provider = _workflow_runtime_worker()
|
||||
if provider is None:
|
||||
return {
|
||||
"inspected": 0,
|
||||
"advanced": 0,
|
||||
"waiting": 0,
|
||||
"failed": 0,
|
||||
}
|
||||
result = dict(provider.reconcile_pending(session, limit=limit))
|
||||
session.commit()
|
||||
return result
|
||||
|
||||
|
||||
@celery.task(
|
||||
name="govoplan.events.dispatch_outbox",
|
||||
bind=True,
|
||||
|
||||
Reference in New Issue
Block a user