Background Jobs Commands
Background job processing commands for managing JoobQ workers and queues.
Overview
The Azu CLI provides comprehensive commands for managing background jobs using the JoobQ framework. These commands handle worker processes, monitor queue status, retry failed jobs, and provide a web interface for job management.
Prerequisites
Before using job commands, ensure:
JoobQ is installed in your project:
azu generate joobqRedis is running:
redis-serverRedis URL is configured:
export REDIS_URL="redis://localhost:6379"
Commands
azu jobs:worker
azu jobs:workerStart background job worker processes to execute queued jobs.
Synopsis
Description
Starts one or more worker processes that poll the job queue and execute background jobs. Workers run continuously until stopped with Ctrl+C.
Options
--workers <n>
-w
Number of worker processes
1
--queues <list>
-q
Comma-separated queue names
default
--daemon
-d
Run as daemon process
false
--verbose
-v
Verbose output
false
Examples
Environment Variables
REDIS_URL
Redis connection URL
redis://localhost:6379
JOOBQ_REDIS_URL
JoobQ-specific Redis URL
Falls back to REDIS_URL
JOOBQ_QUEUE
Default queue name
default
JOOBQ_WORKERS
Number of workers
1
Worker Requirements
The workers expect a src/worker.cr file in your project:
azu jobs:status
azu jobs:statusDisplay current status and statistics for all job queues.
Synopsis
Description
Connects to Redis and displays real-time statistics for all JoobQ queues, including pending, processing, and failed job counts.
Output Format
Examples
Queue States
Pending: Jobs waiting to be processed
Processing: Jobs currently being executed by workers
Failed: Jobs that encountered errors during execution
azu jobs:clear
azu jobs:clearClear jobs from queues.
Synopsis
Description
Remove jobs from specified queues. Use with caution as this operation is irreversible.
Options
--queue <name>
-q
Specific queue to clear (default: default)
--all
Clear all queues
--failed
Clear only failed jobs
--force
-f
Skip confirmation prompt
Examples
Confirmation Prompt
Unless --force is specified, you'll be prompted to confirm:
azu jobs:retry
azu jobs:retryRetry failed jobs.
Synopsis
Description
Re-queue failed jobs for another execution attempt. Useful for recovering from temporary failures like network issues or external service downtime.
Options
--queue <name>
-q
Specific queue (default: default)
--all
Retry all failed jobs
--limit <n>
-l
Maximum number of jobs to retry
Examples
Retry Behavior
Jobs are moved from failed queue to pending queue
Original job parameters and metadata are preserved
Retry count is incremented
Jobs exceeding max retries are not re-queued
azu jobs:ui
azu jobs:uiLaunch the JoobQUI web interface for visual job management.
Synopsis
Description
Starts a web server providing a graphical interface to monitor and manage background jobs. The UI displays real-time statistics, job details, and allows manual job management.
Options
--port <port>
-p
UI server port
4000
--host <host>
-h
UI server host
localhost
--verbose
-v
Verbose output
false
Examples
Web Interface Features
The JoobQUI provides:
Dashboard: Overview of all queues and statistics
Job List: Browse pending, processing, and failed jobs
Job Details: View job parameters, status, and error messages
Retry Controls: Manually retry individual failed jobs
Queue Management: Pause, resume, or clear queues
Real-time Updates: Live statistics and job status
Accessing the UI
Once started, open your browser to:
Or with custom host/port:
Common Workflows
Development Setup
Production Deployment
Queue Monitoring
Handling Failed Jobs
Queue Maintenance
Best Practices
1. Use Multiple Queues
Prioritize jobs by using separate queues:
2. Monitor Queue Health
Regularly check queue status:
3. Set Up Alerting
Monitor for stuck or growing queues:
4. Handle Failed Jobs Promptly
Review and retry or clear failed jobs regularly:
5. Scale Workers Based on Load
Adjust worker count based on queue depth:
Process Management
Using Systemd (Linux)
Create /etc/systemd/system/myapp-workers.service:
Enable and start:
Using Docker
Docker Compose:
Using Foreman
Create Procfile:
Start all services:
Troubleshooting
Workers Not Processing Jobs
Check worker is running:
Verify Redis connection:
Check queue status:
Redis Connection Errors
Verify Redis URL:
Test connection:
Jobs Stuck in Processing
Failed workers may leave jobs in processing state. Clear and retry:
High Memory Usage
Reduce worker count:
Or implement job batching in your application.
Environment Variables
All job commands respect these variables:
REDIS_URL
Primary Redis connection URL
redis://localhost:6379
JOOBQ_REDIS_URL
JoobQ-specific Redis URL
Falls back to REDIS_URL
JOOBQ_QUEUE
Default queue name
default
JOOBQ_WORKERS
Default number of workers
1
Related Commands
azu generate joobq- Set up JoobQ infrastructureazu generate job- Create new job classesazu serve- Development server
See Also
Last updated