A robust, scalable distributed task queue system implemented in Go, designed to handle various types of jobs efficiently.
- Concurrent job processing
- Redis-based queue for job storage and retrieval
- Job scheduling for recurring tasks
- RESTful API for job submission
- Configurable worker count and timeout
- Exponential backoff strategy for efficient queue polling
- Support for multiple job types (email, image resizing, data processing)
- Persistent storage for job results
The worker component is responsible for processing jobs from the queue. It supports:
- Concurrent job processing
- Custom job type handlers
- Exponential backoff for efficient queue polling
The scheduler allows for the creation of recurring jobs. It uses a cron-like syntax for job scheduling.
Implements a Redis-based queue for job storage and retrieval. Supports operations like:
- Enqueue
- Dequeue
- Update job status
Defines the structure for different job types, including:
- Email jobs
- Image resizing jobs
- Data processing jobs
Contains the logic for processing different job types:
- Email sending
- Image resizing
- Data processing
Manages persistent storage of job results using PostgreSQL.
Handles application configuration using Viper, allowing for easy management of:
- Redis connection details
- Worker count and timeout
- API server address
-
Ensure Redis and PostgreSQL are installed and running.
-
Set up the configuration in
config.go
or use environment variables. -
Run the main application:
-
The API server will start, and you can submit jobs via POST requests to
/submit
.
Submit a job:
POST /submit Content-Type: application/json
{ "type": "email", "payload": { "to": "[email protected]", "subject": "Test Email", "body": "This is a test email." } }
The application can be configured using environment variables:
REDISADDR
: Redis server address (default: "127.0.0.1:6379")MAXRETRIES
: Maximum job retry attempts (default: 5)WORKERCOUNT
: Number of concurrent workers (default: 10)APIADDR
: API server address (default: "127.0.0.1:8080")WORKERTIMEOUT
: Worker timeout in seconds (default: 10)
To add new job types:
- Define the job structure in
job.go
- Implement the job handler in
handler.go
- Register the new handler in
main.go
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.