From 9a724edcceee729d9dd36ed4f0353c58b8ca9238 Mon Sep 17 00:00:00 2001 From: rayhpeng Date: Tue, 28 Jul 2026 14:55:29 +0800 Subject: [PATCH] refactor(schedule): group the adapters by context, not by technology MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The inner ring is organised per bounded context; the outer ring was not, so this context's adapters were split across app/infra/persistence/ and app/infra/schedule/ with no principle separating them — one held the SQL repositories, the other held the mapping they both consume, purely because of what technology each touched. Everything the outer ring provides to the schedule context now lives in app/infra/schedule/, mirroring domain/schedule/. That also gives the two remaining adapters an obvious home: the run launcher and the thread lookup are neither persistence nor mapping, and would have needed a third rule under the old layout. Files are moved with git mv so history follows them. app/infra/ persistence/feedback.py stays where it is: it belongs to a separate migration and moving it here would put that work in this diff. The package docstring records the asymmetry rather than leaving it to be rediscovered. --- backend/app/infra/schedule/__init__.py | 11 ++++++++++- .../scheduled_task_runs.py => schedule/run_sql.py} | 0 .../scheduled_tasks.py => schedule/task_sql.py} | 2 ++ backend/tests/test_schedule_fakes.py | 4 ++-- 4 files changed, 14 insertions(+), 3 deletions(-) rename backend/app/infra/{persistence/scheduled_task_runs.py => schedule/run_sql.py} (100%) rename backend/app/infra/{persistence/scheduled_tasks.py => schedule/task_sql.py} (99%) diff --git a/backend/app/infra/schedule/__init__.py b/backend/app/infra/schedule/__init__.py index 71da9cbdc..792b35005 100644 --- a/backend/app/infra/schedule/__init__.py +++ b/backend/app/infra/schedule/__init__.py @@ -1 +1,10 @@ -"""Secondary adapters for the schedule bounded context.""" +"""Secondary adapters for the schedule bounded context. + +Grouped by context rather than by technology, mirroring `domain/schedule/`: +everything the outer ring provides to this one context lives here, whether it +talks to SQL (`task_sql`, `run_sql`), converts a wire/storage shape +(`spec_mapping`), or wraps a runtime. + +`app/infra/persistence/feedback.py` still follows the older technology-first +layout because it belongs to a separate migration; the two will converge. +""" diff --git a/backend/app/infra/persistence/scheduled_task_runs.py b/backend/app/infra/schedule/run_sql.py similarity index 100% rename from backend/app/infra/persistence/scheduled_task_runs.py rename to backend/app/infra/schedule/run_sql.py diff --git a/backend/app/infra/persistence/scheduled_tasks.py b/backend/app/infra/schedule/task_sql.py similarity index 99% rename from backend/app/infra/persistence/scheduled_tasks.py rename to backend/app/infra/schedule/task_sql.py index b4ac3a774..c2f0d029d 100644 --- a/backend/app/infra/persistence/scheduled_tasks.py +++ b/backend/app/infra/schedule/task_sql.py @@ -1,5 +1,7 @@ """SQL adapter for the schedule context's task repository. +Sibling of `run_sql.py`; both consume `spec_mapping` for the stored JSON spec. + Secondary adapter implementing `ScheduledTaskRepository`. SQL/ORM vocabulary stops at this file: methods exchange domain objects and normalize SQLite's tz-naive reads. diff --git a/backend/tests/test_schedule_fakes.py b/backend/tests/test_schedule_fakes.py index 8f632900f..004c55a4f 100644 --- a/backend/tests/test_schedule_fakes.py +++ b/backend/tests/test_schedule_fakes.py @@ -28,8 +28,8 @@ from schedule_fakes import ( InMemoryScheduledTaskRepository, ) -from app.infra.persistence.scheduled_task_runs import SqlScheduledRunRepository -from app.infra.persistence.scheduled_tasks import SqlScheduledTaskRepository +from app.infra.schedule.run_sql import SqlScheduledRunRepository +from app.infra.schedule.task_sql import SqlScheduledTaskRepository from deerflow.config.database_config import DatabaseConfig from deerflow.domain.schedule.model import ( ACTIVE_RUN_STATUSES,