refactor(backend): select() and an inline now everywhere, held by a test
CLAUDE.md's canonical table names SQLAlchemy 2.0 select() and an inline datetime.now(timezone.utc), and both had drifted: five db.query(...) calls remained in routes/auth.py and routes/me.py (seven before the demo went), and four private now helpers stood in sync/videos.py, utils.py (imported as _now by explore and maintenance), scheduler.py (_now_iso) and the e2e seed. All are the canonical form now. Ruff cannot ban a method call on an instance or a function by name, so tests/test_canonical_patterns.py reads every app module's AST and fails on a .query(...) call or a now/_now/now_utc helper — seen red on a planted file.
This commit is contained in:
@@ -106,10 +106,6 @@ def apply_interval(db, job_id: str, minutes: int) -> int:
|
||||
return minutes
|
||||
|
||||
|
||||
def _now_iso() -> str:
|
||||
return datetime.now(timezone.utc).isoformat()
|
||||
|
||||
|
||||
def _record(name: str, **fields) -> None:
|
||||
with _activity_lock:
|
||||
_activity.setdefault(name, {}).update(fields)
|
||||
@@ -187,7 +183,7 @@ def _job(name: str, fn) -> None:
|
||||
db = SessionLocal()
|
||||
actor_id = _manual_actor.get() # set only for a manual "run now" trigger
|
||||
_record(
|
||||
name, last_started=_now_iso(), last_error=None, progress=None
|
||||
name, last_started=datetime.now(timezone.utc).isoformat(), last_error=None, progress=None
|
||||
) # running already claimed
|
||||
|
||||
def sink(current, total, phase):
|
||||
@@ -199,7 +195,7 @@ def _job(name: str, fn) -> None:
|
||||
_record(
|
||||
name,
|
||||
status="skipped",
|
||||
last_finished=_now_iso(),
|
||||
last_finished=datetime.now(timezone.utc).isoformat(),
|
||||
last_result="paused",
|
||||
result=_PAUSED,
|
||||
progress=None,
|
||||
@@ -216,7 +212,7 @@ def _job(name: str, fn) -> None:
|
||||
_record(
|
||||
name,
|
||||
status="ok",
|
||||
last_finished=_now_iso(),
|
||||
last_finished=datetime.now(timezone.utc).isoformat(),
|
||||
last_result=summary,
|
||||
result=data,
|
||||
progress=None,
|
||||
@@ -236,7 +232,7 @@ def _job(name: str, fn) -> None:
|
||||
_record(
|
||||
name,
|
||||
status="error",
|
||||
last_finished=_now_iso(),
|
||||
last_finished=datetime.now(timezone.utc).isoformat(),
|
||||
last_error=err,
|
||||
result=failure,
|
||||
progress=None,
|
||||
|
||||
Reference in New Issue
Block a user