Repository navigation
feat(worker): add a procrastinate background worker - #601
Conversation
|
|
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||
52c1a18 to
1b04005
Compare
1b04005 to
994a500
Compare
994a500 to
f7e99ce
Compare
✅ Validation — PASS (Replicated smoke/no-regression + local worker functional)Tested this PR two ways: the released image on a self-hosted Replicated embedded-cluster install, and the worker itself running locally (per the PR's "How to Test"). Replicated install (external Postgres)
Local worker functional test (at
|
aivong-openhands
left a comment
There was a problem hiding this comment.
Taste rating: 🟢 Good. No material findings.
I checked the worker app, connector and entrypoint against the installed procrastinate 3.10.0 (replace_connector, open_async, run_worker_async), and checked the Makefile wiring and the new psycopg SSL helper. The connector uses the same DbSessionInjector settings as the app server. Its SSL handling follows the existing asyncpg/pg8000 helpers, and it refuses to start with no host, the same way _require_host does. from_env(WorkerConfig, 'OH_WORKER') reads OH_WORKER_CONCURRENCY as described.
I ran test_worker_database.py and test_db_session_injector.py locally against real Postgres, and all 41 passed. The LISTEN/NOTIFY and reconnect tests are meaningful: polling is set to 60s and the job timeout to 20s, so they fail if NOTIFY or the reconnected LISTEN connection doesn't work. CI is green on f7e99ce.
Non-blocking question: The app server uses the Cloud SQL connector when GCP_DB_INSTANCE is set. The worker always connects to DB_HOST. If both are set in a GCP environment, the worker silently connects to whatever DB_HOST points at. That matches the documented cloud-sql-proxy sidecar design, and nothing deploys the worker yet. Still, the coming helm Deployment needs DB_HOST to point at the proxy. Alternatively, the worker could fail fast when GCP_DB_INSTANCE is set and DB_HOST isn't local.
[RISK ASSESSMENT]
[Overall PR]
This PR adds a new process type, but the production deployment and proxy aren't written yet. The change only adds code: nothing in the app server depends on the worker, and no auth, secrets or schema code changes. Reviewer focus: connection-pool sizing (concurrency + 2) once real jobs land in parts 4–5, and how DB_HOST is set for GCP in the helm chart.
Verdict: APPROVE. Keeping the queue in the existing Postgres means no new infrastructure. The trade-off is that jobs now share the main database's connection budget, so pool sizing needs tuning as jobs are added.
This review was created by an AI agent (OpenHands) on behalf of @aivong-openhands.
581e100 to
36fff18
Compare
36fff18 to
ef1d9a6
Compare
|
🚀 Released in 1.69.0. |
HUMAN:
AGENT:
Why
Part 3 of 5 in the sandbox lifecycle stack.
The sandbox lifecycle in part 5 needs periodic jobs that act across every user, and the app has nowhere to run them. procrastinate keeps its queue in the postgres the app already uses, so the worker needs no new service.
procrastinate and its tables are already on main (migration 174, #587). This PR only wires up the worker that runs its jobs. Part 4 adds the maintenance jobs and part 5 adds the sandbox jobs.
Summary
openhands/app_server/worker/holds the app, the database connection and thepython -m openhands.app_server.workerentrypoint.make start-workerruns it, andmake runandmake run-saasnow start it next to the backend.Approach
Suggested reading order:
worker/app.py. One module-levelApp. procrastinate binds each task to the app its blueprint is added to, so there's one per process. The real connection is swapped in when the worker runs (app.replace_connector).worker/__main__.py. Runs the worker with the app server's database settings. It exits when it can't reach the database.OH_WORKER_CONCURRENCYsets how many jobs run at once (default 10).worker/database.py. Builds procrastinate'sPsycopgConnectorfrom those settings. It always connects toDB_HOST. On Cloud SQL, that's acloud-sql-proxysidecar next to the worker.Issue Number
How to Test
uv run pytest tests/unit/app_server/test_worker_database.py make local-db make start-worker # logs worker.startedtest_worker_database.pyruns procrastinate against the test postgres. That includes LISTEN/NOTIFY, and reconnecting after postgres drops every connection.Video/Screenshots
N/A
Type
Notes
cloud-sql-proxysidecar.Enterprise server image for this PR: