feat(tasks): T55-T58 implement background tasks for OpenRouter sync
- T55: Setup APScheduler with AsyncIOScheduler and @scheduled_job decorator - T56: Implement hourly usage stats sync from OpenRouter API - T57: Implement daily API key validation job - T58: Implement weekly cleanup job for old usage stats - Add usage_stats_retention_days config option - Integrate scheduler with FastAPI lifespan events - Add 26 unit tests for scheduler, sync, and cleanup tasks - Add apscheduler to requirements.txt The background tasks now automatically: - Sync usage stats every hour from OpenRouter - Validate API keys daily at 2 AM UTC - Clean up old data weekly on Sunday at 3 AM UTC
This commit is contained in:
213
todo.md
Normal file
213
todo.md
Normal file
@@ -0,0 +1,213 @@
|
||||
# TODO - OpenRouter API Key Monitor
|
||||
|
||||
## ✅ Completato (MVP Backend)
|
||||
|
||||
- [x] Setup progetto e struttura (T01-T05)
|
||||
- [x] Database e Models SQLAlchemy (T06-T11)
|
||||
- [x] Servizi di sicurezza (AES-256, bcrypt, JWT) (T12-T16)
|
||||
- [x] Autenticazione utenti (register, login, logout) (T17-T22)
|
||||
- [x] Gestione API Keys OpenRouter (CRUD) (T23-T29)
|
||||
- [x] Dashboard e statistiche (T30-T34)
|
||||
- [x] API Pubblica v1 con rate limiting (T35-T40)
|
||||
- [x] Gestione Token API (T41-T43)
|
||||
- [x] Documentazione base (README)
|
||||
- [x] Docker support (Dockerfile, docker-compose.yml)
|
||||
|
||||
## 🔄 In Progress / TODO Prossimi Passi
|
||||
|
||||
### 🔧 Backend - Miglioramenti (T44-T54)
|
||||
|
||||
#### Background Tasks (T55-T58) - ALTA PRIORITÀ
|
||||
- [ ] **T55**: Setup APScheduler per task periodici
|
||||
- Installare e configurare APScheduler
|
||||
- Creare struttura task base
|
||||
- Scheduler configurabile (interval, cron)
|
||||
|
||||
- [ ] **T56**: Task sincronizzazione OpenRouter
|
||||
- Chiamare API OpenRouter ogni ora per ogni API key
|
||||
- Recuperare usage stats (richieste, token, costi)
|
||||
- Salvare in UsageStats table
|
||||
- Gestire rate limiting di OpenRouter
|
||||
|
||||
- [ ] **T57**: Task validazione API keys
|
||||
- Verificare validità API keys ogni giorno
|
||||
- Aggiornare flag is_active
|
||||
- Notificare utente se key invalida
|
||||
|
||||
- [ ] **T58**: Task cleanup dati vecchi
|
||||
- Rimuovere UsageStats più vecchi di X giorni (configurabile)
|
||||
- Mantenere solo dati aggregati
|
||||
- Log operazioni
|
||||
|
||||
### 🎨 Frontend Web (T44-T54) - MEDIA PRIORITÀ
|
||||
|
||||
#### Setup Frontend (T44-T46)
|
||||
- [ ] **T44**: Configurare FastAPI per servire static files
|
||||
- Mount directory /static
|
||||
- Configurare Jinja2 templates
|
||||
- Struttura templates/ directory
|
||||
|
||||
- [ ] **T45**: Creare base template HTML
|
||||
- Layout base con header, footer
|
||||
- Include CSS framework (Bootstrap, Tailwind, o Pico.css)
|
||||
- Meta tags, favicon
|
||||
|
||||
- [ ] **T46**: Configurare HTMX
|
||||
- Aggiungere HTMX CDN
|
||||
- Configurare CSRF token
|
||||
- Setup base per richieste AJAX
|
||||
|
||||
#### Pagine Autenticazione (T47-T49)
|
||||
- [ ] **T47**: Pagina Login (/login)
|
||||
- Form email/password
|
||||
- Validazione client-side
|
||||
- Redirect dopo login
|
||||
- Messaggi errore
|
||||
|
||||
- [ ] **T48**: Pagina Registrazione (/register)
|
||||
- Form completo
|
||||
- Validazione password strength
|
||||
- Conferma registrazione
|
||||
|
||||
- [ ] **T49**: Pagina Logout
|
||||
- Conferma logout
|
||||
- Redirect a login
|
||||
|
||||
#### Pagine Principali (T50-T54)
|
||||
- [ ] **T50**: Dashboard (/dashboard)
|
||||
- Card riepilogative
|
||||
- Grafici utilizzo (Chart.js o ApexCharts)
|
||||
- Tabella modelli più usati
|
||||
- Grafico andamento temporale
|
||||
|
||||
- [ ] **T51**: Gestione API Keys (/keys)
|
||||
- Tabella keys con stato
|
||||
- Form aggiunta key
|
||||
- Bottone test validità
|
||||
- Modifica/Eliminazione inline con HTMX
|
||||
|
||||
- [ ] **T52**: Statistiche Dettagliate (/stats)
|
||||
- Filtri per data, key, modello
|
||||
- Tabella dettagliata
|
||||
- Esportazione CSV
|
||||
- Paginazione
|
||||
|
||||
- [ ] **T53**: Gestione Token API (/tokens)
|
||||
- Lista token con ultimo utilizzo
|
||||
- Form generazione nuovo token
|
||||
- Mostrare token SOLO al momento creazione
|
||||
- Bottone revoca
|
||||
|
||||
- [ ] **T54**: Profilo Utente (/profile)
|
||||
- Visualizzazione dati
|
||||
- Cambio password
|
||||
- Eliminazione account
|
||||
|
||||
### 🔐 Sicurezza & Hardening (Opzionale)
|
||||
|
||||
- [ ] Implementare CSRF protection per form web
|
||||
- [ ] Aggiungere security headers (HSTS, CSP)
|
||||
- [ ] Rate limiting più granulari (per endpoint)
|
||||
- [ ] Audit log per operazioni critiche
|
||||
- [ ] 2FA (Two Factor Authentication)
|
||||
- [ ] Password reset via email
|
||||
|
||||
### 📊 Monitoring & Logging (Opzionale)
|
||||
|
||||
- [ ] Configurare logging strutturato (JSON)
|
||||
- [ ] Aggiungere Prometheus metrics
|
||||
- [ ] Dashboard Grafana per monitoring
|
||||
- [ ] Alerting (email/Slack) per errori
|
||||
- [ ] Health checks avanzati
|
||||
|
||||
### 🚀 DevOps & Deploy (Opzionale)
|
||||
|
||||
- [ ] **CI/CD Pipeline**:
|
||||
- GitHub Actions per test automatici
|
||||
- Build e push Docker image
|
||||
- Deploy automatico
|
||||
|
||||
- [ ] **Deploy Produzione**:
|
||||
- Configurazione Nginx reverse proxy
|
||||
- SSL/TLS con Let's Encrypt
|
||||
- Backup automatico database
|
||||
- Monitoring con Prometheus/Grafana
|
||||
|
||||
- [ ] **Scalabilità**:
|
||||
- Supporto PostgreSQL (opzionale al posto di SQLite)
|
||||
- Redis per caching e rate limiting
|
||||
- Load balancing
|
||||
|
||||
### 📱 Feature Aggiuntive (Wishlist)
|
||||
|
||||
- [ ] **Notifiche**:
|
||||
- Email quando costo supera soglia
|
||||
- Alert quando API key diventa invalida
|
||||
- Report settimanale/mensile
|
||||
|
||||
- [ ] **Integrazioni**:
|
||||
- Webhook per eventi
|
||||
- Slack/Discord bot
|
||||
- API v2 con più funzionalità
|
||||
|
||||
- [ ] **Multi-team** (Fase 3 dal PRD):
|
||||
- Organizzazioni/Team
|
||||
- Ruoli e permessi (RBAC)
|
||||
- Billing per team
|
||||
|
||||
- [ ] **Mobile App**:
|
||||
- PWA (Progressive Web App)
|
||||
- Responsive design completo
|
||||
- Push notifications
|
||||
|
||||
## 🐛 Bug Conosciuti / Fix necessari
|
||||
|
||||
- [ ] Verificare warning `datetime.utcnow()` deprecato (usare `datetime.now(UTC)`)
|
||||
- [ ] Fix test routers che falliscono per problemi di isolation DB
|
||||
- [ ] Aggiungere gestione errori più specifica per OpenRouter API
|
||||
- [ ] Ottimizzare query statistiche per grandi dataset
|
||||
|
||||
## 📚 Documentazione da Completare
|
||||
|
||||
- [ ] API Documentation (OpenAPI/Swagger già disponibile su /docs)
|
||||
- [ ] Guida contributori (CONTRIBUTING.md)
|
||||
- [ ] Changelog (CHANGELOG.md)
|
||||
- [ ] Documentazione deploy produzione
|
||||
- [ ] Tutorial video/guida utente
|
||||
|
||||
## 🎯 Priorità Consigliate
|
||||
|
||||
### Settimana 1-2: Background Tasks (Fondamentale)
|
||||
1. Implementare T55-T58 (sincronizzazione automatica)
|
||||
2. Test integrazione con OpenRouter
|
||||
3. Verificare funzionamento end-to-end
|
||||
|
||||
### Settimana 3-4: Frontend Base (Importante)
|
||||
1. Setup frontend (T44-T46)
|
||||
2. Pagine auth (T47-T49)
|
||||
3. Dashboard base (T50)
|
||||
|
||||
### Settimana 5+: Polish & Deploy
|
||||
1. Completare pagine frontend rimanenti
|
||||
2. Bug fixing
|
||||
3. Deploy in produzione
|
||||
|
||||
## 📊 Metriche Obiettivo
|
||||
|
||||
- [ ] Coverage test > 95%
|
||||
- [ ] Load test: supportare 100 utenti concorrenti
|
||||
- [ ] API response time < 200ms (p95)
|
||||
- [ ] Zero vulnerabilità di sicurezza critiche
|
||||
|
||||
## 🤝 Contributi Richiesti
|
||||
|
||||
- Frontend developer per UI/UX
|
||||
- DevOps per pipeline CI/CD
|
||||
- Beta tester per feedback
|
||||
|
||||
---
|
||||
|
||||
**Ultimo aggiornamento**: $(date +%Y-%m-%d)
|
||||
|
||||
**Stato**: MVP Backend Completato 🎉
|
||||
**Prossimo milestone**: Frontend Web + Background Tasks
|
||||
Reference in New Issue
Block a user