{"id":6598,"library":"django-q2","title":"Django Q2","description":"Django Q2 is a native Django task queue, scheduler, and worker application using Python multiprocessing. It is a maintained fork of the original Django Q project, offering asynchronous tasks, scheduled jobs, and Django Admin integration. The current version is 1.9.0, and it has an active release cadence with multiple updates per year, regularly incorporating support for newer Django and Python versions.","status":"active","version":"1.9.0","language":"en","source_language":"en","source_url":"https://github.com/django-q2/django-q2","tags":["django","task queue","async","worker","scheduler","multiprocessing"],"install":[{"cmd":"pip install django-q2","lang":"bash","label":"Install latest version"},{"cmd":"pip install django-q2[redis]","lang":"bash","label":"Install with Redis broker support"}],"dependencies":[{"reason":"Core framework dependency; version compatibility is crucial. Requires Django >=4.2.","package":"Django","optional":false},{"reason":"Used to store args, kwargs, and result objects in the database.","package":"django-picklefield","optional":false},{"reason":"Required if using Redis as the message broker.","package":"redis","optional":true},{"reason":"Optional, but recommended for more reliable CPU count detection and better monitoring on some operating systems (e.g., OS X, Windows).","package":"psutil","optional":true}],"imports":[{"note":"Primary function to enqueue a task for asynchronous execution.","symbol":"async_task","correct":"from django_q.tasks import async_task"},{"note":"Used to create scheduled, cron, or repeated tasks.","symbol":"schedule","correct":"from django_q.tasks import schedule"},{"note":"Django model for managing scheduled tasks programmatically.","symbol":"Schedule","correct":"from django_q.models import Schedule"}],"quickstart":{"code":"import os\nimport django\nfrom django.conf import settings\n\n# Minimal Django setup if running outside a full Django environment\nif not settings.configured:\n    settings.configure(\n        INSTALLED_APPS=[\n            'django_q',\n            # Add other apps if needed\n        ],\n        DATABASES={\n            'default': {\n                'ENGINE': 'django.db.backends.sqlite3',\n                'NAME': ':memory:',\n            }\n        },\n        Q_CLUSTER={\n            'name': 'myproject',\n            'workers': 4,\n            'timeout': 90,\n            'compress': True,\n            'save_limit': 250,\n            'queue_limit': 500,\n            'cpu_affinity': 1,\n            'label': 'Django Q2',\n            'redis': os.environ.get('REDIS_URL', 'redis://localhost:6379/0'),\n        },\n        SECRET_KEY=os.environ.get('DJANGO_SECRET_KEY', 'a-very-secret-key-for-development'),\n        TIME_ZONE='UTC',\n        USE_TZ=True,\n    )\ndjango.setup()\n\n# Your task function (e.g., in a tasks.py file)\ndef my_long_running_task(iterations):\n    result = 0\n    for i in range(iterations):\n        result += i\n    return result\n\n# Enqueue the task\nfrom django_q.tasks import async_task\ntask_id = async_task('my_app.tasks.my_long_running_task', 1000000)\nprint(f\"Task enqueued with ID: {task_id}\")\n\n# To run the cluster in a separate terminal:\n# python manage.py qcluster\n","lang":"python","description":"To get started, add 'django_q' to your `INSTALLED_APPS` and configure `Q_CLUSTER` in your `settings.py`. Ensure you run `python manage.py migrate` to create necessary database tables. Define your task functions and enqueue them using `async_task`. Finally, start the Q2 cluster with `python manage.py qcluster` to process tasks in the background. The example above demonstrates a basic setup and how to enqueue a task, assuming a Django project structure."},"warnings":[{"fix":"Upgrade your Python version to 3.9 or newer before upgrading `django-q2` to version 1.8.0 or later.","message":"Python 3.8 support was dropped in `django-q2` v1.8.0. Ensure your Python environment is 3.9 or higher when upgrading.","severity":"breaking","affected_versions":">=1.8.0"},{"fix":"Upgrade your Django project to version 4.2 or later before upgrading `django-q2` to version 1.7.0 or later.","message":"Django 3.2 and 4.1 support was dropped in `django-q2` v1.7.0. Subsequent versions require Django 4.2 or newer, with v1.9.0 adding support for Django 6.0.","severity":"breaking","affected_versions":">=1.7.0"},{"fix":"Upgrade `django-q2` to v1.9.0 or newer if you are using `redis-py` version 5 or greater.","message":"If using Redis as your broker, `django-q2` v1.9.0 introduced a fix for compatibility with `redis-py > 5`. Ensure you are on `django-q2` v1.9.0 or higher if using recent `redis-py` versions to avoid potential issues.","severity":"gotcha","affected_versions":"<1.9.0 with redis-py > 5"},{"fix":"Ensure `SECRET_KEY` is set in your Django settings, especially in production environments.","message":"The `SECRET_KEY` in your Django settings is crucial as Django Q2 uses it to sign task packages. Without a properly set `SECRET_KEY`, tasks might fail to unpack or execute securely.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade to `django-q2` v1.7.0 or newer to correctly handle `max_attempts=1`.","message":"A bug existed in versions prior to 1.7.0 where setting `max_attempts` to 1 would still result in the task being retried once. This could lead to unexpected duplicate executions.","severity":"gotcha","affected_versions":"<1.7.0"},{"fix":"Uninstall `django-q` and `pip install django-q2`. Then run `python manage.py migrate`.","message":"The original `django-q` project is no longer maintained. Users are strongly advised to migrate to `django-q2` for continued support and updates. Migration typically involves uninstalling `django-q` and installing `django-q2`.","severity":"deprecated","affected_versions":"Users of `django-q`"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}