Fix scheduler for cloud run #30
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request updates the scheduler logic in
backend/app/main.pyto 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:
ForecastSchedulerandEvaluationScheduler) are no longer started by default on Cloud Run; instead, they are only enabled if theENABLE_BACKGROUND_SCHEDULERenvironment variable is set totrue. This prevents jobs from being killed when Cloud Run scales down.New HTTP Trigger Endpoint:
/scheduler/trigger-forecastto 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: