- Go 1.24 or higher
- Redis server (optional, will use mock queue if unavailable)
# Clone the repository
git clone https://github.com/mstfsu/go-tasks.git
cd go-tasks
# Install dependencies
go mod download
# Build the application
make build
# Binary will be created at: ./bin/go-tasks# Start Redis (if using Docker)
docker run -d -p 6379:6379 redis:alpine
# Run the server
./bin/go-tasks
# Or with custom Redis configuration
REDIS_ADDR=localhost:6379 REDIS_PASSWORD=yourpassword ./bin/go-tasks- 🌐 Dashboard: http://localhost:8080
- 📡 REST API: http://localhost:8080/api/v1/
- 📊 Metrics: http://localhost:8080/metrics
- 🔌 gRPC: localhost:50051
┌──────────────────┐
│ Web Dashboard │
│ (Real-time UI) │
└────────┬─────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ API Layer │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ REST API │ │ gRPC Server │ │
│ │ (Gin) │ │ (Protocol) │ │
│ └──────┬───────┘ └──────┬───────┘ │
└─────────┼──────────────────────────────┼───────────┘
│ │
▼ ▼
┌─────────────────────────────────────────────────────┐
│ Queue Layer (Redis) │
│ • Priority Queue • Distributed • Persistent │
└────────┬────────────────────────────────┬───────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ Worker Pool │ │ Scheduler │
│ • Concurrent │ │ • Cron Jobs │
│ • Retry Logic │ │ • Recurring │
│ • Callbacks │ │ • Timezone │
└────────┬────────┘ └─────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ Monitoring & Metrics │
│ • Prometheus Export • Task Stats • Health Check │
└─────────────────────────────────────────────────────┘
curl -X POST http://localhost:8080/api/v1/tasks \
-H "Content-Type: application/json" \
-d '{
"name": "process_user_data",
"payload": {"user_id": 123, "action": "export"},
"priority": 10
}'curl http://localhost:8080/api/v1/tasks/{task_id}curl -X POST http://localhost:8080/api/v1/scheduler/jobs \
-H "Content-Type: application/json" \
-d '{
"name": "daily_cleanup",
"schedule": "0 0 * * *",
"task_name": "cleanup_task",
"payload": {}
}'import "github.com/mstfsu/go-tasks/proto"
client := proto.NewTaskServiceClient(conn)
response, err := client.CreateTask(ctx, &proto.CreateTaskRequest{
Name: "process_data",
Payload: `{"key": "value"}`,
Priority: 5,
})| Component | Technology |
|---|---|
| Language | Go 1.24+ |
| Queue | Redis 6.0+ |
| REST Framework | Gin |
| RPC | gRPC + Protocol Buffers |
| Scheduler | robfig/cron |
| Metrics | Prometheus |
| Testing | testify |
| Frontend | HTML5 + Vanilla JS |
┌─────────────────────────────────────────────────────┐
│ Queue Layer (Redis) │
│ • Priority Queue • Distributed • Persistent │
└────────┬────────────────────────────────┬───────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ Worker Pool │ │ Scheduler │
│ • Concurrent │ │ • Cron Jobs │
│ • Retry Logic │ │ • Recurring │
│ • Callbacks │ │ • Timezone │
└────────┬────────┘ └─────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ Monitoring & Metrics │
│ • Prometheus Export • Task Stats • Health Check │
└─────────────────────────────────────────────────────┘
```un the server (with Redis)
REDIS_ADDR=localhost:6379 ./bin/go-tasks
# Run without Redis (uses mock queue)
./bin/go-tasks
# Access dashboard at http://localhost:8080
# API endpoints at http://localhost:8080/api/v1/
# Metrics at http://localhost:8080/metrics
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Client │────▶│ Broker │────▶│ Worker │
│ (REST/gRPC)│ │ (Redis) │ │ Pool │
└─────────────┘ └─────────────┘ └─────────────┘
│ │
▼ ▼
┌─────────────┐ ┌─────────────┐
│ Scheduler │ │ Metrics │
│ (Cron) │ │(Prometheus) │
└─────────────┘ └─────────────┘
go-tasks/
├── cmd/
│ └── server/ # Main server application
├── internal/
│ ├── task/ # Task models and lifecycle
│ ├── queue/ # Queue interface + Redis/Mock implementations
│ ├── worker/ # Worker pool with retry logic
│ ├── retry/ # Exponential backoff retry handler
│ ├── scheduler/ # Cron-based job scheduler
│ ├── api/ # REST API (Gin) + recent tasks tracking
│ ├── grpc/ # gRPC server implementation
│ └── metrics/ # Prometheus metrics collector
├── proto/ # Protocol buffer definitions
├── web/
│ └── templates/ # Dashboard HTML templates
├── Makefile # Build and test commands
└── README.md
# Run all tests
make test
# Run tests with coverage
go test -v -cover ./...
# Run specific package tests
go test -v ./internal/worker/Test Coverage: 72 comprehensive tests across all modules
- ✅ Task lifecycle and state management
- ✅ Queue operations (enqueue, dequeue, priority)
- ✅ Worker pool concurrency and shutdown
- ✅ Retry mechanism with backoff
- ✅ Scheduler job execution
- ✅ API endpoints (REST + gRPC)
- ✅ Metrics collection and export
# Redis Configuration
REDIS_ADDR=localhost:6379 # Redis server address
REDIS_PASSWORD= # Redis password (optional)
REDIS_DB=0 # Redis database number
# Server Configuration
SERVER_PORT=8080 # HTTP server port
GRPC_PORT=50051 # gRPC server port
# Worker Configuration
NUM_WORKERS=2 # Number of concurrent workers
POLL_INTERVAL=1s # Queue polling interval
SHUTDOWN_TIMEOUT=10s # Graceful shutdown timeoutworkerConfig := worker.WorkerConfig{
NumWorkers: 2, // Concurrent workers
PollInterval: time.Second, // How often to check queue
ShutdownTimeout: 10 * time.Second, // Graceful shutdown time
RetryConfig: retry.RetryConfig{
MaxRetries: 3,
InitialInterval: time.Second,
MaxInterval: time.Minute,
Multiplier: 2.0,
},
}- Microservices: Decouple services with async task processing
- ETL Pipelines: Process large datasets in background
- Email/Notifications: Send bulk communications asynchronously
- Data Export: Generate and deliver reports on demand
- Scheduled Tasks: Run periodic cleanup, backups, aggregations
- Webhook Processing: Handle webhook callbacks reliably
- Image/Video Processing: Process media files in background
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
⭐ Star this repo if you find it useful!
Made with ❤️ by mstfsu
- Go 1.21+
- Redis 6.0+
- Docker (optional)
go mod downloadgo test ./...go run cmd/server/main.gogo run cmd/worker/main.goThis project is being built step-by-step with comprehensive testing at each stage.
MIT


