A lightweight job-processing microservice that accepts text-processing jobs via REST, processes them asynchronously (simulated heavy work), persists state/results in SQLite, and exposes endpoints to submit and query jobs.
- POST /jobs to submit a job
- GET /jobs/{job_id} to fetch status and result
- Background processing using Tokio tasks
- SQLite persistence with connection pooling via sqlx
- Tests: unit and integration
- Rust toolchain (1.62+ recommended)
- cargo available
Optional environment variables
- DATABASE_URL - SQLite connection string. Defaults to sqlite://jobs.db .
- BIND_ADDR - server bind address. Defaults to 127.0.0.1:8080 .
cargo build --releaserun with default SQLite file 'jobs.db' in the working directory
cargo run --releaseor set a different database or bind address
DATABASE_URL="sqlite://./my_jobs.db" BIND_ADDR="0.0.0.0:8080" cargo run --releaseOn first run the service will create the jobs table if it does not exist.
POST /jobs
Request JSON
{ "input": "some text" }Response JSON
{ "job_id": "<uuid>" }Behavior
Inserts a new row with status = "pending"
Spawns a background task that updates status to running, sleeps 5 seconds, computes reverse(input), and sets status to completed with the result.
Example curl
curl -s -X POST http://127.0.0.1:8080/jobs
-H "Content-Type: application/json"
-d '{"input": "hello world"}'
GET /jobs/{job_id}
Response JSON
{
"job_id": "<uuid>",
"status": "pending|running|completed|failed",
"result": "<string|null>",
"created_at": "<RFC3339>",
"updated_at": "<RFC3339>"
}Example curl
curl -s http://127.0.0.1:8080/jobs/<job_id> | jq