refactor(schedule): move orchestrator to application/ + review fixes (stage 8)

Follow-up to the layered refactor (review-driven):

- Move scheduling/orchestrator.py -> application/orchestrator.py
  (orchestrator is application-level coordination, not a cron-trigger
  primitive; matches the intended target tree)
- Migrate orchestrator re-exports from scheduling/__init__.py to
  application/__init__.py; scheduling/ now exposes only CronScheduler
- Rewrite imports + 5 mock.patch string targets in test_janitor.py and
  the orchestrator import in test_layering.py
- Update docstring refs in application/service.py + execution/worker.py
- Add 4 runner smoke tests (test_layering.py): _limited_log under-limit /
  empty-sentinel / above-MAX_LOG_BYTES truncation; execute_artifact
  rejects unsupported script_type with ValueError
- infrastructure/__init__.py re-exports SchedulerStorageClient so
  ``from schedule.infrastructure import SchedulerStorageClient`` is a
  stable top-level surface
- CLAUDE.md engineering note: extend the commit trail to 7476c27 and
  note the stage-8 orchestrator placement

Zero behavior change; schedule/pyproject.toml untouched. 29 tests green.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-09-02 10:10:41 +08:00
committed by tao.chen
co-authored by Claude
parent ff03a79938
commit d196b237a7
9 changed files with 83 additions and 30 deletions
+6 -6
View File
@@ -23,7 +23,7 @@ import pytest
from common.db.models import ScheduleNodeRuns
from common.eventing import utcnow
from schedule.scheduling.orchestrator import NODE_FINISHED_EVENT, DispatchOrchestrator
from schedule.application.orchestrator import NODE_FINISHED_EVENT, DispatchOrchestrator
def _make_orchestrator() -> DispatchOrchestrator:
@@ -195,7 +195,7 @@ async def test_reap_kills_running_row_past_deadline() -> None:
fake_session.add = MagicMock()
with patch(
"schedule.scheduling.orchestrator.session_scope",
"schedule.application.orchestrator.session_scope",
return_value=_open_session_scope(fake_session),
):
killed = await orch._reap_stuck_node_runs()
@@ -223,7 +223,7 @@ async def test_reap_skips_healthy_row() -> None:
fake_session.add = MagicMock()
with patch(
"schedule.scheduling.orchestrator.session_scope",
"schedule.application.orchestrator.session_scope",
return_value=_open_session_scope(fake_session),
):
killed = await orch._reap_stuck_node_runs()
@@ -266,7 +266,7 @@ async def test_reap_processes_multiple_rows_in_one_pass() -> None:
fake_session.add = MagicMock()
with patch(
"schedule.scheduling.orchestrator.session_scope",
"schedule.application.orchestrator.session_scope",
return_value=_open_session_scope(fake_session),
):
killed = await orch._reap_stuck_node_runs()
@@ -289,7 +289,7 @@ async def test_janitor_loop_propagates_cancellation() -> None:
raise asyncio.CancelledError
with patch(
"schedule.scheduling.orchestrator.asyncio.sleep",
"schedule.application.orchestrator.asyncio.sleep",
side_effect=cancel_on_sleep,
):
with pytest.raises(asyncio.CancelledError):
@@ -321,7 +321,7 @@ async def test_janitor_loop_continues_after_reap_exception() -> None:
raise asyncio.CancelledError
with patch(
"schedule.scheduling.orchestrator.asyncio.sleep",
"schedule.application.orchestrator.asyncio.sleep",
side_effect=_count_sleeps,
):
with pytest.raises(asyncio.CancelledError):