Skip to content

Conversation

@amrit110
Copy link
Member

This pull request updates the scheduler logic in backend/app/main.py to better support deployment on Cloud Run by decoupling background job execution from the application process. Instead, it introduces HTTP endpoints that can be triggered externally (e.g., by Cloud Scheduler), and ensures background jobs only run locally when explicitly enabled. It also improves shutdown handling for schedulers.

Key changes:

Cloud Run / Scheduler Adaptation:

  • Background schedulers (ForecastScheduler and EvaluationScheduler) are no longer started by default on Cloud Run; instead, they are only enabled if the ENABLE_BACKGROUND_SCHEDULER environment variable is set to true. This prevents jobs from being killed when Cloud Run scales down.
  • Informational log messages have been updated to clarify whether background schedulers are running or if HTTP endpoints should be used for triggering jobs.

New HTTP Trigger Endpoint:

  • Added a new POST endpoint /scheduler/trigger-forecast to manually trigger a forecast run via HTTP. This endpoint is designed for use with Cloud Scheduler and ensures that forecast jobs run to completion within an active HTTP request. It includes logic to prevent duplicate runs if a job is already in progress.

Improved Scheduler Shutdown Handling:

  • The shutdown logic now checks if schedulers are running before attempting to stop them, improving robustness when stopping the application.

@amrit110 amrit110 self-assigned this Dec 10, 2025
@amrit110 amrit110 added bug Something isn't working enhancement New feature or request labels Dec 10, 2025
@amrit110 amrit110 merged commit 4a0b59a into main Dec 10, 2025
7 checks passed
@amrit110 amrit110 deleted the fix_scheduler branch December 10, 2025 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants