Summary
init_scheduler() is called at module import level (bottom of app.py). This means it fires on:
- Every gunicorn worker process (scheduled posts fire N times with N workers)
- Every
pytest import (background jobs run during the test suite)
- Every hot reload in development
Impact
Duplicate post publishing in production. Flaky tests. Unpredictable behavior on Railway with multiple workers.
Fix
# Option A — guard with __main__
if __name__ == '__main__':
init_scheduler()
app.run()
For multi-worker production, use APScheduler's Postgres jobstore so only one worker claims each job, or run the scheduler as a dedicated worker process via the Procfile.
Effort: ~30 minutes
Part of full audit: #1
Summary
init_scheduler()is called at module import level (bottom ofapp.py). This means it fires on:pytestimport (background jobs run during the test suite)Impact
Duplicate post publishing in production. Flaky tests. Unpredictable behavior on Railway with multiple workers.
Fix
For multi-worker production, use APScheduler's Postgres jobstore so only one worker claims each job, or run the scheduler as a dedicated worker process via the
Procfile.Effort: ~30 minutes