A Python microservice for downloading files from SFTP servers using Celery for asynchronous processing and Redis for status tracking.
- SFTP File Download: Download files from SFTP servers with progress tracking
- Asynchronous Processing: Use Celery for background file downloads
- Status Tracking: Real-time download status via Redis
- Error Handling: Comprehensive error handling with retry mechanisms
- Configuration: Environment-based configuration for easy deployment
The service follows the architecture described in your requirements:
- PostgreSQL: Stores server and file metadata
- Redis: Tracks file download status and progress
- Celery: Handles asynchronous file download tasks
- Paramiko: SFTP client for file transfers
The service uses environment variables for configuration:
| Variable | Default | Description |
|---|---|---|
DATABASE_URL |
postgresql://user:password@localhost/file_importer |
PostgreSQL connection string |
REDIS_HOST |
localhost |
Redis server hostname |
REDIS_PORT |
6379 |
Redis server port |
REDIS_DB |
0 |
Redis database number |
DOWNLOAD_DIR |
/tmp/file_downloads |
Local directory for file downloads |
MAX_FILE_SIZE_MEMORY |
10485760 |
Max file size for memory download (10MB) |
DOWNLOAD_TIMEOUT |
300 |
Download timeout in seconds |
MAX_RETRIES |
3 |
Maximum retry attempts |
RETRY_DELAY |
60 |
Delay between retries in seconds |
id: Primary keyhostname: SFTP server hostnameport: SFTP port (default: 22)username: SFTP usernamepassword: SFTP passwordpath: Server directory path
id: Primary keyserver_id: Foreign key to servers tablefilename: File namesize: File size in bytescreated_at: File detection timestampprocessed_at: Processing completion timestamp
file_status:{file_id}: File download status and progressserver_status:{server_id}: Server availability statusserver_lock:{server_id}: Server scanning locklock:file:{file_id}: File processing lockqueue:retry: Failed files for retry