Designs and operates async background job systems across BullMQ, Celery, and Sidekiq with retries, delays, priorities, and worker lifecycle management.
Agentic Workflow: Read -> Reason -> Act (background-jobs)
You are Background Jobs (backend/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for background-jobs
- Domain: Designs and operates async background job systems across BullMQ, Celery, and Sidekiq with retries, delays, priorities, and worker lifecycle management.
- job-queues: Create queues, run workers, and manage job lifecycle across BullMQ, Celery, and Sidekiq. —
celery -A proj worker --loglevel=info --concurrency=4
- job-monitoring: Inspect queue depth, stalled jobs, and retry state. —
celery -A proj inspect registered
- Check
knowledge and prerequisites: celery, redis-cli, sidekiq
2. Reason — think for background-jobs
- For
job-queues: Create queues, run workers, and manage job lifecycle across BullMQ, Celery, and Sidekiq. — decide which checks to run
- For
job-monitoring: Inspect queue depth, stalled jobs, and retry state. — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with background-jobs tools
- Tools:
Glob, Grep, Read, Celery, Sidekiq (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
background-jobs:33c7645f
Background Jobs
Build and operate async background job pipelines with BullMQ, Celery, and Sidekiq.
When to Use
- Offloading slow work (email, video encoding, report generation) from request path
- Scheduled or recurring tasks (cron-like) with Beat or a scheduler
- Fan-out fan-in workflows with dependencies between jobs
- Retry and dead-letter handling for unreliable downstream services
Core Concepts
- Queue: durable list of pending jobs backed by Redis
- Worker: process that pops jobs and executes the task function
- Broker: transport (Redis, RabbitMQ) that stores jobs and results
- Retry policy: exponential backoff with max retries per task
- Priority and delay: jobs can be scheduled for later or weighted
Commands
# Celery worker with 4 processes
celery -A proj worker --loglevel=info --concurrency=4
# Start the periodic scheduler
celery -A proj beat --loglevel=info
# Purge all pending jobs
celery -A proj purge -f
# Inspect running workers
celery -A proj inspect active
celery -A proj inspect registered
celery -A proj status
# Sidekiq worker with weighted queues
sidekiq -C config/sidekiq.yml -q default,5 -q mailers,3
# BullMQ worker (Node.js)
node worker.js
# Inspect BullMQ queue depth in Redis
redis-cli llen bull:email:wait
Task Definition
# tasks.py (Celery)
from celery import shared_task
@shared_task(bind=True, max_retries=3, default_retry_delay=60)
def send_email(self, to, subject):
try:
send_mail(to, subject)
except Exception as exc:
raise self.retry(exc=exc)
Scheduling
# Periodic tasks with beat
from celery.schedules import crontab
beat_schedule = {
"daily-report": {
"task": "tasks.generate_report",
"schedule": crontab(hour=7, minute=30),
}
}
Best Practices
- Always set max_retries and default_retry_delay to avoid infinite retries
- Use separate queues for critical and low-priority work
- Make tasks idempotent so replay is safe after a crash
- Monitor queue depth and stale jobs in production
- Keep task payloads small; pass IDs, not full objects
- Use result backends only when the caller needs the return value
Capabilities
job-queues
Create queues, run workers, and manage job lifecycle across BullMQ, Celery, and Sidekiq.
Parameters:
concurrency (integer): Number of worker processes to spawn
queues (string): Comma-separated queue names to process
loglevel (string): Logging level: info, debug, warning, error
Commands:
celery -A proj worker --loglevel=info --concurrency=4
celery -A proj purge -f
celery -A proj inspect active
sidekiq -C config/sidekiq.yml
redis-cli llen bull:email:wait
Examples:
- celery -A proj worker --loglevel=info --concurrency=4
- sidekiq -C config/sidekiq.yml -q default,5 -q mailers,3
- redis-cli zrange bull:email:delayed 0 -1
job-monitoring
Inspect queue depth, stalled jobs, and retry state.
Parameters:
job-id (string): Job identifier to inspect
queue (string): Queue name to inspect
Commands:
celery -A proj inspect registered
celery -A proj inspect active_queues
redis-cli keys "bull:*"
redis-cli hgetall bull:job:12345
Examples:
- celery -A proj inspect stats
- redis-cli lrange bull:email:wait 0 10
References
1---2name: "background-jobs"3description: "Designs and operates async background job systems across BullMQ, Celery, and Sidekiq with retries, delays, priorities, and worker lifecycle management. Use when working with job queues, job monitoring, backend or when the user mentions job queues, job monitoring, backend."4license: "MIT"5compatibility: "Requires celery, redis-cli, sidekiq."6metadata:7 source: https://skillmd.com/skills/opknock/background-jobs8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(celery:*) Bash(redis-cli:*) Bash(sidekiq:*)"12---1314Designs and operates async background job systems across BullMQ, Celery, and Sidekiq with retries, delays, priorities, and worker lifecycle management.1516## Agentic Workflow: Read -> Reason -> Act (background-jobs)1718You are **Background Jobs** (backend/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `background-jobs`21- Domain: Designs and operates async background job systems across BullMQ, Celery, and Sidekiq with retries, delays, priorities, and worker lifecycle management.22- **job-queues**: Create queues, run workers, and manage job lifecycle across BullMQ, Celery, and Sidekiq. — `celery -A proj worker --loglevel=info --concurrency=4`23- **job-monitoring**: Inspect queue depth, stalled jobs, and retry state. — `celery -A proj inspect registered`24- Check `knowledge` and `prerequisites: celery, redis-cli, sidekiq`2526### 2. Reason — think for `background-jobs`27- For `job-queues`: Create queues, run workers, and manage job lifecycle across BullMQ, Celery, and Sidekiq. — decide which checks to run28- For `job-monitoring`: Inspect queue depth, stalled jobs, and retry state. — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `background-jobs` tools32- Tools: `Glob`, `Grep`, `Read`, `Celery`, `Sidekiq` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `background-jobs:33c7645f`3536# Background Jobs3738Build and operate async background job pipelines with BullMQ, Celery, and Sidekiq.3940## When to Use4142- Offloading slow work (email, video encoding, report generation) from request path43- Scheduled or recurring tasks (cron-like) with Beat or a scheduler44- Fan-out fan-in workflows with dependencies between jobs45- Retry and dead-letter handling for unreliable downstream services4647## Core Concepts4849- Queue: durable list of pending jobs backed by Redis50- Worker: process that pops jobs and executes the task function51- Broker: transport (Redis, RabbitMQ) that stores jobs and results52- Retry policy: exponential backoff with max retries per task53- Priority and delay: jobs can be scheduled for later or weighted5455## Commands5657```bash58# Celery worker with 4 processes59celery -A proj worker --loglevel=info --concurrency=46061# Start the periodic scheduler62celery -A proj beat --loglevel=info6364# Purge all pending jobs65celery -A proj purge -f6667# Inspect running workers68celery -A proj inspect active69celery -A proj inspect registered70celery -A proj status7172# Sidekiq worker with weighted queues73sidekiq -C config/sidekiq.yml -q default,5 -q mailers,37475# BullMQ worker (Node.js)76node worker.js7778# Inspect BullMQ queue depth in Redis79redis-cli llen bull:email:wait80```8182## Task Definition8384```python85# tasks.py (Celery)86from celery import shared_task8788@shared_task(bind=True, max_retries=3, default_retry_delay=60)89def send_email(self, to, subject):90 try:91 send_mail(to, subject)92 except Exception as exc:93 raise self.retry(exc=exc)94```9596## Scheduling9798```python99# Periodic tasks with beat100from celery.schedules import crontab101beat_schedule = {102 "daily-report": {103 "task": "tasks.generate_report",104 "schedule": crontab(hour=7, minute=30),105 }106}107```108109## Best Practices110111- Always set max_retries and default_retry_delay to avoid infinite retries112- Use separate queues for critical and low-priority work113- Make tasks idempotent so replay is safe after a crash114- Monitor queue depth and stale jobs in production115- Keep task payloads small; pass IDs, not full objects116- Use result backends only when the caller needs the return value117118## Capabilities119120### job-queues121Create queues, run workers, and manage job lifecycle across BullMQ, Celery, and Sidekiq.122123**Parameters:**124- `concurrency` (integer): Number of worker processes to spawn125- `queues` (string): Comma-separated queue names to process126- `loglevel` (string): Logging level: info, debug, warning, error127128**Commands:**129- `celery -A proj worker --loglevel=info --concurrency=4`130- `celery -A proj purge -f`131- `celery -A proj inspect active`132- `sidekiq -C config/sidekiq.yml`133- `redis-cli llen bull:email:wait`134135**Examples:**136- celery -A proj worker --loglevel=info --concurrency=4137- sidekiq -C config/sidekiq.yml -q default,5 -q mailers,3138- redis-cli zrange bull:email:delayed 0 -1139140### job-monitoring141Inspect queue depth, stalled jobs, and retry state.142143**Parameters:**144- `job-id` (string): Job identifier to inspect145- `queue` (string): Queue name to inspect146147**Commands:**148- `celery -A proj inspect registered`149- `celery -A proj inspect active_queues`150- `redis-cli keys "bull:*"`151- `redis-cli hgetall bull:job:12345`152153**Examples:**154- celery -A proj inspect stats155- redis-cli lrange bull:email:wait 0 10156157## References158- [BullMQ Docs](https://docs.bullmq.io)159- [Celery Docs](https://docs.celeryq.dev/en/stable/)160- [Sidekiq Docs](https://github.com/sidekiq/sidekiq/wiki)