Skip to main content

An extension for django and huey that supports multi queue management

Project description

License: MIT Version

django-huey


This package is an extension of huey contrib djhuey package that allows users to manage multiple queues.

Compatible versions

Package Version
Django 5.0
Django 4.2
Django 3.2
huey 2.5
huey 2.4

Installation

Using pip package manager run:

pip install django-huey

Then, in your settings.py file add django_huey to the INSTALLED_APPS:

INSTALLED_APPS = [
	...
    'django_huey',
]

Configuration

In settings.py you must add the DJANGO_HUEY setting:

DJANGO_HUEY = {
    'default': 'first', #this name must match with any of the queues defined below.
    'queues': {
        'first': {#this name will be used in decorators below
            'huey_class': 'huey.RedisHuey',  
            'name': 'first_tasks',  
            'consumer': {
                'workers': 2,
                'worker_type': 'thread',
            },
        },
        'emails': {#this name will be used in decorators below
            'huey_class': 'huey.RedisHuey',  
            'name': 'emails_tasks',  
            'consumer': {
                'workers': 5,
                'worker_type': 'thread',
            },
        }
    }
}

Including queues from files

new in 1.1.0

You can also include a queue configuration from another file, located in one of your apps. Use django_huey.utils.include to do so:

In settings.py you may have:

DJANGO_HUEY = {
    'default': 'first', #this name must match with any of the queues defined below.
    'queues': {
        # Your current queues definitions
    }
}

# This is new
from django_huey.utils import include
DJANGO_HUEY["queues"].update(include("example_app.queues"))

And in your example_app.queues:

queues = {
    "test": {
        "huey_class": "huey.MemoryHuey",
        "results": True,
        "store_none": False,
        "immediate": False,
        "utc": True,
        "blocking": True,
        "consumer": {
            "workers": 1,
            "worker_type": "thread",
            "initial_delay": 0.1,
            "backoff": 1.15,
            "max_delay": 10.0,
            "scheduler_interval": 60,
            "periodic": True,
            "check_worker_health": True,
            "health_check_interval": 300,
        },
    },
}

Note: in your queues file, you should declare a variable called queues, so they can be included. If the variable doesn't exist, an AttributeError will be raised.

Usage

Now you will be able to run multiple queues using:

python manage.py djangohuey --queue first
python manage.py djangohuey --queue emails

Each queue must be run in a different terminal.

If you defined a default queue, you can just run:

python manage.py djangohuey

And the default queue will be used.

Configuring tasks

You can use usual huey decorators to register tasks, but they must be imported from django_huey as shown below:

from django_huey import db_task, task

@task() #Use the default queue 'first'
def some_func_that_uses_default_queue():
    # perform some db task
    pass

@db_task(queue='first')
def some_func():
    # perform some db task
    pass

@task(queue='emails')
def send_mails():
	# send some emails
    pass

All the args and kwargs defined in huey decorators should work in the same way, if not, let us know.

Importing a huey instance

Sometimes you'll need to import a huey instance in order to do some advanced configuration, for example, when using huey pipelines.

You can do that by using the get_queue function from django_huey:

from django_huey import get_queue

first_q = get_queue('first')

@first_q.task()
def some_func():
    pass

Integration with huey monitor

You can use django-huey with huey monitor.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_huey-1.2.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

django_huey-1.2.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file django_huey-1.2.1.tar.gz.

File metadata

  • Download URL: django_huey-1.2.1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.12

File hashes

Hashes for django_huey-1.2.1.tar.gz
Algorithm Hash digest
SHA256 634abf1e707acef90dd00df4267458486f89a3117419000ec5584b1c4129701a
MD5 7c595b89ba27e53cec334d0da2ccb816
BLAKE2b-256 3d0ca1da34c09fb5a0cc629026835fc5a46fb28a6ff208527d6b004bd685dfbb

See more details on using hashes here.

File details

Details for the file django_huey-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: django_huey-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.12

File hashes

Hashes for django_huey-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 59c82b72fd4b6e60c219bd1fbab78acfe68a1c8d3efb1d3e42798a67d01a4aa2
MD5 8bcdbf98a5fa94545be64ed7e5d50a4e
BLAKE2b-256 bd46019699f3dcf2777f07b1d5465c7a4cf3d7e73b6f9e0ad8de53c73e3f9191

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page