forked from 0xWheatyz/SPARC
Refactor scheduler.py to use the application-level pooled DatabaseClient #1658
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
SPARC/scheduler.pyinstantiates its ownDatabaseClientat the top ofrun_scheduled_analysis()without reusing the application-level singleton fromauth.pyor any shared pool. Under concurrent load this creates an extra database connection outside the pool, and it mirrors the same anti-pattern that was fixed inauth.pyfor P1.What to do
Refactor
run_scheduled_analysis()to accept an optionaldb_client: DatabaseClient | None = Noneparameter:auth.get_db_client()start_scheduler()inscheduler.pyto wire the shared client at startupAcceptance criteria
run_scheduled_analysis()no longer creates aDatabaseClientunconditionallyapi.pypasses the pooled client when starting the schedulerruff check SPARC/andpytest tests/ -vboth passRoadmap reference
Follow-up to the P1 refactor of
auth.pyconnection pooling.PR #1665 has been created for this issue. Work was completed on branch and is ready for review.
Closed via PR #1665. Reviewed and merged. The refactor correctly replaces per-invocation DatabaseClient instantiation in scheduler.py with the shared pooled client from SPARC.auth.get_db_client(). Removed db.connect(), db.initialize_schema(), and db.close() calls since the pooled singleton handles lifecycle. Note: PR #1667 (issue #1656) scheduler tests were updated to match this refactor before merging.