Metadata-Version: 2.1
Name: django-huey
Version: 1.0.1
Summary: An extension for django and huey that supports multi queue management
Home-page: https://github.com/gaiacoop/django-huey
Author: GAIA - Cooperativa de desarrollo de software
Author-email: contacto@gaiacoop.tech
License: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 3
Classifier: Framework :: Django :: 2.2
Classifier: Framework :: Django :: 3.1
Classifier: Framework :: Django :: 3.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENCE

![Version](https://img.shields.io/badge/version-1.0.1-informational.svg)

# django-huey

This package is an extension of [huey](https://github.com/coleifer/huey) contrib djhuey package that allows users to manage multiple queues.

## Compatible versions
| Package     | Version     |
| ----------- | ----------- |
| Django      | 3.2         |
| huey        | 2.4         |

## Installation

Using pip package manager run:
```
pip install django-huey
```

Note: use a virtualenv to isolate your dependencies.

Then, in your **settings.py** file add django_huey to the INSTALLED_APPS:
```python
INSTALLED_APPS = [
	...
    'django_huey',
]
```

## Configuration
In **settings.py** you must add the DJANGO_HUEY setting:
```python
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',
            },
        }
    }
}
```

### 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:

```python
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:
```python
from django_huey import get_queue

first_q = get_queue('first')

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

