feat(backend): implement postgres job queue

This commit is contained in:
2026-06-21 01:39:32 +03:30
parent d95f3c27c1
commit 24a025587e
29 changed files with 1466 additions and 0 deletions

41
backend/README.md Normal file
View File

@@ -0,0 +1,41 @@
# Backend
Django REST Framework backend for the minimal queue.
The backend owns two models:
- `Job`
- `JobEvent`
Workers do not call public claim endpoints. The worker command imports the same service functions that API views use for creation, retry, stats, and event reads.
## API
```http
GET /api/health/
POST /api/jobs/
GET /api/jobs/
GET /api/jobs/{id}/
GET /api/jobs/{id}/events/
GET /api/job-events/?after_id=123&limit=100
GET /api/jobs/stats/
POST /api/jobs/{id}/retry/
```
## Worker
```powershell
python manage.py run_job_workers
```
Worker settings come from environment variables:
```env
JOB_WORKER_THREADS=4
JOB_WORKER_POLL_INTERVAL_MS=500
JOB_WORKER_LEASE_SECONDS=30
JOB_WORKER_CLEANUP_INTERVAL_SECONDS=5
JOB_WORKER_BACKOFF_BASE_SECONDS=5
JOB_WORKER_BACKOFF_MAX_SECONDS=300
JOB_WORKER_MAX_ATTEMPTS_DEFAULT=3
```