Skip to content

Feat/background harvester - #12

Merged
Matheus904-12 merged 4 commits into
mainfrom
feat/background-harvester
May 7, 2026
Merged

Matheus904-12 merged 4 commits into
mainfrom
feat/background-harvester

Conversation

@Matheus904-12

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings May 7, 2026 23:35
@vercel

vercel Bot commented May 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
weather-api Ready Ready Preview, Comment May 7, 2026 11:41pm

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 BackgroundScheduler that calls GetWeatherUseCase.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 thread backend/main.py
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}")

Comment thread README.md
- [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 thread README.md
Comment on lines 20 to 23
subgraph Interface
R[weather_router.py]
T[test_api.py]
S[scheduler.py]
end
@Matheus904-12
Matheus904-12 merged commit a3be21a into main May 7, 2026
4 checks passed

This branch was successfully deployed

1 active deployment
Preview — f622bfb6 Deployed May 7, 2026 by vercel[bot]
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.

feat: implementar um cron job para busca temporarias

2 participants