Skip to content

Conversation

adamantike
Copy link
Contributor

Description
For steps that need to run before the web application starts, such as scheduling tasks, this new startup.py script is introduced.

This fixes a recently introduced issue where task scheduling was not being triggered, because of it being included in the if __name__ == "__main__": block, which is not executed when the application is run by Gunicorn in production environments.

We do not include this logic as part of FastAPI's lifespan implementation, as running multiple workers with Gunicorn would cause this logic to be executed multiple times.

Checklist

  • I've tested the changes locally
  • I've updated relevant comments
  • I've assigned reviewers for this PR
  • I've added unit tests that cover the changes

For steps that need to run before the web application starts, such as
scheduling tasks, this new `startup.py` script is introduced.

This fixes a recently introduced issue where task scheduling was not
being triggered, because of it being included in the
`if __name__ == "__main__":` block, which is not executed when
the application is run by Gunicorn in production environments.

We do not include this logic as part of FastAPI's lifespan
implementation, as running multiple workers with Gunicorn would
cause this logic to be executed multiple times.
@adamantike adamantike requested review from gantoine and zurdi15 August 13, 2025 02:17
Copy link

trunk-io bot commented Aug 13, 2025

Running Code Quality on PRs by uploading data to Trunk will soon be removed. You can still run checks on your PRs using trunk-action - see the migration guide for more information.

Copy link

Test Results

548 tests  ±0   547 ✅ ±0   57s ⏱️ -1s
  1 suites ±0     1 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 63f84b7. ± Comparison against base commit 6b31a64.

Copy link

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
8773 6187 71% 0% 🟢

New Files

File Coverage Status
backend/startup.py 50% 🟢
TOTAL 50% 🟢

Modified Files

File Coverage Status
backend/main.py 92% 🟢
TOTAL 92% 🟢

updated for commit: 63f84b7 by action🐍

Copy link
Member

@gantoine gantoine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to me!

@adamantike adamantike merged commit 57e9a9f into master Aug 13, 2025
9 checks passed
@adamantike adamantike deleted the misc/create-startup-script branch August 13, 2025 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants