Prompt
How do I schedule delayed jobs in a background worker?
Latest observation
Oct 24, 2026
OpenAI APIWeb search: off
Scheduling delayed jobs in a background worker usually means: enqueue the job now, but don’t execute it until a specified time in the future.
The exact approach depends on the stack, but the common patterns are:
1) Use the queue’s built-in delayed/ETA support
Many job systems let you specify a delay or run-at time.
Examples:
- Sidekiq:
perform_in(10.minutes, args...)orperform_at(time, args...) - Celery:
apply_async(countdown=600)orapply_async(eta=run_time) - Bull/BullMQ:
queue.add(name, data, { delay: 600000 }) - RQ: use a scheduler plugin or separate scheduler service
- RabbitMQ / plain queues: often requires a delayed-message plugin or custom scheduling logic
2) Store scheduled jobs in a database or persistent store
If your worker system doesn’t support delay natively:
- Save jobs with a
run_attimestamp - Run a scheduler process that periodically:
- finds due jobs (
run_at <= now) - enqueues them to the worker queue
- marks them as dispatched
- finds due jobs (
This is common for:
- custom background worker setups
- systems needing reliability across restarts
- recurring jobs
3) Use a separate scheduler process
A typical architecture:
- App/API: creates delayed job record
- Scheduler: scans for due jobs every few seconds/minutes
- Worker(s): process jobs normally once enqueued
This avoids making workers responsible for sleeping and waiting.
4) Don’t have workers “sleep” for long delays
Avoid doing this:
- worker picks up job
- sleeps for 10 minutes
- then processes
Problems:
- wastes worker threads/processes
- reduces throughput
- can break restarts/retries
- harder to scale
Best practice
Prefer:
- native delayed job support if available
- otherwise persistent scheduled jobs + scheduler service
Simple generic example
Pseudo-code:
# when scheduling
db.insert({
"job_type": "send_email",
"payload": {"user_id": 123},
"run_at": now + 10*60
})
# scheduler loop
while True:
due_jobs = db.query("SELECT * FROM jobs WHERE run_at <= now AND status='pending'")
for job in due_jobs:
queue.enqueue(job)
db.update(job.id, status="queued")
sleep(5)
If you tell me what language/framework/queue system you’re using, I can show the exact way to schedule delayed jobs there.