Skip to content

[P0] init_scheduler() at module level — fires on every gunicorn worker #3

Description

@ShadowWalkerNC

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions