Skip to content

How to Fix Python Arq Scheduler Task Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Python Arq Scheduler Task Error. We cover key concepts, practical examples, and best practices.

Arq tasks do not execute when the Redis connection fails, the task function is not properly defined, or the cron expression is invalid.

The Wrong Way

from arq import create_pool
from arq.connections import RedisSettings

async def my_task(ctx):
    return "done"

async def main():
    pool = await create_pool(RedisSettings())
    result = await pool.submit_job('my_task', _job_id='test')
    print(result)

Output:

arq.exceptions.JobNotFound: Job not found

The Right Way

from arq import create_pool, cron
from arq.connections import RedisSettings

async def my_task(ctx):
    print("Task executed")
    return "done"

class WorkerSettings:
    functions = [my_task]
    redis_settings = RedisSettings(host='localhost', port=6379)

Run the worker:

arq myapp.WorkerSettings

Submit a job:

import asyncio
from arq import create_pool
from arq.connections import RedisSettings

async def submit():
    pool = await create_pool(RedisSettings())
    result = await pool.submit_job('my_task', _job_id='test')
    print(result)
    await pool.close()

asyncio.run(submit())

Output:

Task executed
JobResult(...)

Prevention Tips

  • Define WorkerSettings with a functions list and redis_settings.
  • Run arq WorkerSettings in a separate process.
  • Use cron() for scheduled tasks with cron expressions.
  • Use _job_id for idempotent job submission.
  • Handle JobNotFound and ConnectionError in production.

Common Mistakes with arq scheduler

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world PYTHON code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between Arq and Celery?

Arq is a lightweight job queue using Redis. Celery supports multiple brokers, result backends, and complex routing. Arq is simpler and ideal for smaller projects that only need Redis.

How do I schedule recurring tasks with Arq?

Define a function decorated with @cron() or add it to WorkerSettings.cron_jobs. The cron expression follows standard cron format: cron(minute, hour, day, month, day_of_week).

Why does Arq say "Job not found"?

The job may have expired before you checked. Arq expires completed jobs quickly by default. Use keep_result parameter when submitting to extend retention. Also verify the task function name matches.

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro