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:
60
docker-compose.yml
Normal file
60
docker-compose.yml
Normal file
@@ -0,0 +1,60 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: openrouter-watcher
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8000:8000"
|
||||
environment:
|
||||
- DATABASE_URL=sqlite:///./data/app.db
|
||||
- SECRET_KEY=${SECRET_KEY:-change-this-secret-key-in-production}
|
||||
- ENCRYPTION_KEY=${ENCRYPTION_KEY:-change-this-encryption-key-in-prod}
|
||||
- OPENROUTER_API_URL=https://openrouter.ai/api/v1
|
||||
- MAX_API_KEYS_PER_USER=10
|
||||
- MAX_API_TOKENS_PER_USER=5
|
||||
- RATE_LIMIT_REQUESTS=100
|
||||
- RATE_LIMIT_WINDOW=3600
|
||||
- JWT_EXPIRATION_HOURS=24
|
||||
- DEBUG=false
|
||||
- LOG_LEVEL=INFO
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
- ./logs:/app/logs
|
||||
networks:
|
||||
- openrouter-network
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
|
||||
# Servizio opzionale per backup automatico (commentato)
|
||||
# backup:
|
||||
# image: busybox
|
||||
# container_name: openrouter-backup
|
||||
# volumes:
|
||||
# - ./data:/data:ro
|
||||
# - ./backups:/backups
|
||||
# command: >
|
||||
# sh -c "while true; do
|
||||
# sleep 86400 &&
|
||||
# cp /data/app.db /backups/app-$$(date +%Y%m%d).db
|
||||
# done"
|
||||
# restart: unless-stopped
|
||||
# networks:
|
||||
# - openrouter-network
|
||||
|
||||
networks:
|
||||
openrouter-network:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
data:
|
||||
driver: local
|
||||
logs:
|
||||
driver: local
|
||||
Reference in New Issue
Block a user