修复调度运行失败
This commit is contained in:
@@ -133,6 +133,13 @@ class Settings(BaseSettings):
|
||||
)
|
||||
|
||||
# ── schedule execution tuning ────────────────────────────────
|
||||
schedule_event_namespace: str = Field(
|
||||
default="model-platform-local",
|
||||
description=(
|
||||
"Namespace prepended to schedule outbox event types. Each "
|
||||
"deployment that shares a database must use a unique value."
|
||||
),
|
||||
)
|
||||
schedule_execution_concurrency: int = Field(
|
||||
default=4,
|
||||
description=(
|
||||
|
||||
@@ -5,6 +5,7 @@ from typing import Any
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from common.config import settings
|
||||
from common.db.models import OutboxEvents
|
||||
from common.ids import new_ulid
|
||||
|
||||
@@ -20,6 +21,19 @@ def event_time(value: datetime | None = None) -> str:
|
||||
return item.astimezone(UTC).isoformat().replace("+00:00", "Z")
|
||||
|
||||
|
||||
def schedule_event_type(event_type: str) -> str:
|
||||
"""Return the deployment-scoped schedule event type.
|
||||
|
||||
Multiple development deployments currently share one MySQL database.
|
||||
Scoping the event type prevents a scheduler from another deployment from
|
||||
claiming and acknowledging work that only this deployment can execute.
|
||||
"""
|
||||
namespace = settings.schedule_event_namespace.strip().strip(".")
|
||||
if not namespace:
|
||||
raise ValueError("SCHEDULE_EVENT_NAMESPACE must not be empty")
|
||||
return f"{namespace}.{event_type}"
|
||||
|
||||
|
||||
async def add_outbox_event(
|
||||
session: AsyncSession,
|
||||
*,
|
||||
@@ -50,5 +64,10 @@ async def add_outbox_event(
|
||||
return item
|
||||
|
||||
|
||||
__all__ = ["add_outbox_event", "event_time", "utcnow"]
|
||||
__all__ = [
|
||||
"add_outbox_event",
|
||||
"event_time",
|
||||
"schedule_event_type",
|
||||
"utcnow",
|
||||
]
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ from common.db.models import (
|
||||
Scripts,
|
||||
Versions,
|
||||
)
|
||||
from common.eventing import add_outbox_event, utcnow
|
||||
from common.eventing import add_outbox_event, schedule_event_type, utcnow
|
||||
from common.ids import new_ulid
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@ async def create_scheduled_run(
|
||||
|
||||
await add_outbox_event(
|
||||
session,
|
||||
event_type="schedule.run.requested",
|
||||
event_type=schedule_event_type("schedule.run.requested"),
|
||||
producer="platform-api",
|
||||
trace_id=trace_id,
|
||||
aggregate_type="schedule_run",
|
||||
|
||||
Reference in New Issue
Block a user