Configuration
JoobQ provides various configuration options to tailor its behavior to your specific application needs. In this section, we will guide you through how to customize JoobQ, connect it to Redis, and configure job options.
The JoobQ.configure
block allows you to:
Centralize Configuration: Define all your queues, schedules, and global settings in one place.
Optimize Performance: Set worker counts, job retries, and throttling to match your application's requirements.
Enhance Flexibility: Schedule jobs using cron patterns or time intervals, and integrate custom middlewares to extend functionality.
Improve Reliability: Enable retries, dead-letter queues, and expiration settings to ensure jobs are processed and errors are handled gracefully.
Monitor and Control: Enable optional features like REST APIs and statistics tracking for better system visibility.
Key Features of JoobQ Configuration
Queue Management: Define multiple queues with specific worker counts and job types.
Job Scheduling: Schedule tasks with precision using cron expressions or periodic intervals.
Global Customization: Set defaults for retries, timeouts, and job expiration.
Extensibility: Add custom middlewares for advanced use cases.
Resilience: Leverage throttling, retries, and dead-letter queues for fault tolerance.
Configuration Guide
This guide provides an overview of configuring JoobQ, a job queue system designed for the Crystal programming language. You will learn how to define queues, set up middlewares, schedule jobs, and customize various options to suit your needs.
Define Configuration
Use the JoobQ.configure
block to set up your job queue system. This is where you define queues, schedule jobs, and set global options.
Key Features and Configuration Options
1. Queues
Define queues to manage jobs. Each queue can be customized with:
A name.
The number of workers.
The job class to process the tasks.
Optional throttling limits.
Example:
Parameters:
name
- A unique string identifying the queue.workers
- Number of worker threads to handle jobs in the queue.job
- The job class responsible for processing tasks.throttle
(optional) - Limits the number of tasks processed per period.
2. Scheduling Jobs
Jobs can be scheduled using either cron expressions or time intervals.
Using cron
:
Using every
:
every
:3. Global Settings
JoobQ provides several global configuration options:
time_location
Time::Location.load("America/New_York")
Globally sets the default timezone for JoobQ
rest_api_enabled
false
Enables REST API for queue management.
stats_enabled
true
Enables gathering of queue statistics.
default_queue
"default"
Name of the default queue.
retries
3
Number of retries for failed jobs.
expires
3.days
Time before a queued job expires.
timeout
2.seconds
Timeout for job execution.
failed_ttl
3.milliseconds
Time to retain failed job logs.
dead_letter_ttl
7.days
Time to retain dead-letter jobs.
Example:
4. Middlewares
JoobQ supports middlewares to modify job execution behavior. Middlewares are applied in the following order:
Throttle - Limits job execution rate.
Retry - Handles job retries on failure.
Timeout - Enforces execution time limits.
Adding Custom Middleware:
5. Time Location
You can set the global time location for scheduling jobs. By default, it uses "America/New_York"
.
Example:
Example: Full Configuration
Below is a complete example of a JoobQ configuration:
Conclusion
Configuring JoobQ properly allows you to fine-tune its performance, reliability, and responsiveness according to your application’s needs. Now that you understand configuration, let’s dive into some Advanced Features that JoobQ has to offer!
Last updated