Skip to content

Go-based task pool system with asynchronous processing, worker pool concurrency, PostgreSQL persistence, and a Gin-powered REST API. Dockerized and designed for correctness, safety, and clean architecture.

License

Notifications You must be signed in to change notification settings

amirhasanpour/task-pool

Repository files navigation

Task Pool System API

A concurrent task processing system built in Go, designed to demonstrate safe worker-pool concurrency, RESTful API design, and clean application structure. The system allows clients to submit tasks, processes them asynchronously using a configurable worker pool, and exposes APIs to monitor task status and pool statistics. The application is containerized with Docker and uses PostgreSQL for persistent task storage.


Features and Tools

  • Asynchronous task processing using an idiomatic Go worker-pool pattern
  • Safe concurrency with buffered channels, contexts, and graceful shutdown handling
  • RESTful API built with Gin for HTTP routing and request handling
  • Persistent task storage using PostgreSQL
  • Database access and migrations managed with GORM
  • Configurable application settings using Viper with support for YAML config files and environment variables
  • Configurable task pool size and worker count
  • Clear task state machine (pending, processing, completed, failed)
  • Graceful shutdown ensuring in-flight tasks complete before exit
  • Containerized application using Docker
  • Local service orchestration with Docker Compose
  • Clean, layered project structure separating handlers, services, repositories, and workers
  • Unit tests covering handlers, services, and worker pool behavior
  • Race-condition–safe design, verifiable with Go’s -race detector

How to run?

Using Docker Compose

cd to the project directory and run this command:

docker-compose up --build -d

to stop all services:

docker-compose down

to stop services and remove database volumes:

docker-compose down -v

API Endpoints

Create a New Task

curl -X POST "http://localhost:8080/api/v1/tasks" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Process Data",
    "description": "Process customer data for analytics"
  }'

Get Task by ID

curl -X GET "http://localhost:8080/api/v1/tasks/550e8400-e29b-41d4-a716-446655440000"

List All Tasks

curl -X GET "http://localhost:8080/api/v1/tasks"

Get Pool Statistics

curl -X GET "http://localhost:8080/api/v1/pool/stats"

Endpoints Scripts


Run Tests

go test ./test/...
go test ./test/... -race

Run Service Tests separately

go test ./test/service -v
go test ./test/service -race -v

Run Woker Tests separately

go test ./test/worker -v
go test ./test/worker -race -v

Run Handler Tests separately

go test ./test/handler -v
go test ./test/handler -race -v

About

Go-based task pool system with asynchronous processing, worker pool concurrency, PostgreSQL persistence, and a Gin-powered REST API. Dockerized and designed for correctness, safety, and clean architecture.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published