Feat/background harvester - #12
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds a background “harvester” to periodically prefetch weather data for a fixed set of cities (warming Redis cache and persisting to MongoDB), and updates project documentation to reflect the new behavior.
Changes:
- Introduces an APScheduler
BackgroundSchedulerthat callsGetWeatherUseCase.execute()for a predefined city list every 60 minutes. - Wires scheduler lifecycle into FastAPI startup/shutdown in
backend/main.py. - Updates README to describe the background harvester and adjusts the architecture diagram/roadmap.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| README.md | Updates documentation/diagram/roadmap to highlight the new background harvester. |
| backend/src/infrastructure/scheduler.py | Adds the APScheduler-based background job setup for periodic city harvesting. |
| backend/main.py | Starts/stops the scheduler during FastAPI app startup/shutdown. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1
to
+5
| from apscheduler.schedulers.background import BackgroundScheduler | ||
| from src.application.use_cases import GetWeatherUseCase | ||
|
|
||
| CITIES_TO_WATCH = ["São Paulo", "Londres", "Nova York", "Tóquio"] | ||
|
|
Comment on lines
+57
to
+61
| # 5. Iniciar o Scheduler (Robô Coletor) | ||
| @app.on_event("startup") | ||
| def startup_event(): | ||
| app.state.scheduler = setup_weather_scheduler(weather_service) | ||
| print("Robô Coletor de Clima iniciado com sucesso!") |
Comment on lines
+1
to
+18
| from apscheduler.schedulers.background import BackgroundScheduler | ||
| from src.application.use_cases import GetWeatherUseCase | ||
|
|
||
| CITIES_TO_WATCH = ["São Paulo", "Londres", "Nova York", "Tóquio"] | ||
|
|
||
| def setup_weather_scheduler(weather_service: GetWeatherUseCase): | ||
| scheduler = BackgroundScheduler() | ||
|
|
||
| def fetch_all_watched_cities(): | ||
| print(f"Robo Coletor: Iniciando busca para {len(CITIES_TO_WATCH)} cidades...") | ||
| for city in CITIES_TO_WATCH: | ||
| try: | ||
| weather_service.execute(city) | ||
| print(f"Clima de {city} coletado e persistido.") | ||
| except Exception as e: | ||
| print(f"Erro ao coletar {city}: {e}") | ||
|
|
||
| scheduler.add_job(fetch_all_watched_cities, 'interval', minutes=60) |
Comment on lines
+6
to
+17
| def setup_weather_scheduler(weather_service: GetWeatherUseCase): | ||
| scheduler = BackgroundScheduler() | ||
|
|
||
| def fetch_all_watched_cities(): | ||
| print(f"Robo Coletor: Iniciando busca para {len(CITIES_TO_WATCH)} cidades...") | ||
| for city in CITIES_TO_WATCH: | ||
| try: | ||
| weather_service.execute(city) | ||
| print(f"Clima de {city} coletado e persistido.") | ||
| except Exception as e: | ||
| print(f"Erro ao coletar {city}: {e}") | ||
|
|
| - [x] Fase 4: Histórico de Buscas com MongoDB. | ||
| - [x] Fase 5: Qualidade & Automação (Testes & CI). ✅ | ||
| - [x] Fase 5: Qualidade & Automação (Testes & CI). | ||
| - [x] Bônus: Robô Coletor de Dados (Cronjob). ✅ |
Comment on lines
20
to
23
| subgraph Interface | ||
| R[weather_router.py] | ||
| T[test_api.py] | ||
| S[scheduler.py] | ||
| end |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.