Skip to main content

hueyx

PyPI version

A django extension to run huey with multiple queues. Multiple queues allow tasks to not block each other and to scale independently. Only the redis storage is supported.


Important
  • If you use huey 1.x then install hueyx 0.1.2. Checkout the git tag huey1.x.
  • If you use huey 2.x then install hueyx >= 1.0.

Usage

Install it with

pip install hueyx

Add hueyx in your installed apps.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'hueyx',
]
settings.py

Compared to djhuey, hueyx allows several queues to be defined in the settings.py.

HUEYX = {
    'queue_name1': {
        'connection': {
            'host': 'localhost',
            'port': 6379,
            'db': 0,
        },
        'consumer': {
            'workers': 1,
            'worker_type': 'process',
        }
    },
    'queue_name2': {
        'connection': {
            'connection_pool': ConnectionPool(host='localhost', port=6379, db=1)
        },
        'consumer': {
            'multiple_scheduler_locking': True,
            'prometheus_metrics': True,
            'workers': 2,
            'worker_type': 'thread',
        }
    },
    'priority_queue_name3': {
        'huey_class': 'huey.PriorityRedisHuey',
        'connection': {
            'connection_pool': ConnectionPool(host='localhost', port=6379, db=1)
        },
        'consumer': {
            'multiple_scheduler_locking': True,
            'prometheus_metrics': True,
            'workers': 2,
            'worker_type': 'thread',
        }
    },
}

The settings are almost the same as in djhuey. Have a look at the huey documentation to see the exact parameter usage.

Exceptions:

  • You can only configure redis as storage engine by configure huey_class to huey.RedisHuey, huey.PriorityRedisHuey, huey.RedisExpireHuey or huey.PriorityRedisExpireHuey.
  • The name and backend_class parameters are not supported.
  • The options multiple_scheduler_locking and prometheus_metrics_enabled have been added. See below.
  • The parameters heartbeat_timeout for db_task has been added. See below.
tasks.py
from hueyx.queues import hueyx

"""
Define which queue you want to use.
They are predefined in settings.py.
"""
HUEY_Q1 = hueyx('queue_name1')
HUEY_Q2 = hueyx('queue_name2')


@HUEY_Q1.task()
def my_task1():
    print('my_task1 called')

@HUEY_Q1.db_task()
def my_db_task1():
    print('my_db_task1 called')

@HUEY_Q2.task()
def my_task2():
    print('my_task2 called')

@HUEY_Q2.periodic_task(crontab(minute='0', hour='3'))
def my_periodic_task2():
    print('my_periodic_task2 called')
    return 1

@HUEY_Q2.db_task(heartbeat_timeout=120)
def my_heartbeat_task(heartbeat: Heartbeat):
    with heartbeat.long_running_operation():
        print('This operation can take a while -> don\'t check for heartbeats')
    print('Now we check for heartbeats -> call heartbeat() periodically')
    heartbeat()
Push task to queue
from example.tasks import my_task1, my_db_task1, my_task2


my_task1()  # Task for queue_name1
my_db_task1()  # Task for queue_name1
my_task2()  # Task for queue_name2
Run consumer

Consumers are started with the queue_name.

./manage.py run_hueyx queue_name1
Heartbeat tasks

Heartbeat tasks are tasks with the parameter heartbeat_timeout. It defines the timeout in seconds. They get a Heartbeat object which needs to be called in order to send a heartbeat to redis. If no heartbeat occurs in set timeout the task is presumed to be dead and will automatically get restarted. heartbeat_timeout needs to be at least 120 seconds. It does not work together with the parameter include_task.

Additional settings

multiple_scheduler_locking

multiple_scheduler_locking has been added to support multiple huey schedulers. If you run huey in a cloud environment, you will end up running multiple huey instances which each will schedule the periodic task. multiple_scheduler_locking prevents periodic tasks to be scheduled multiple times. It is false by default.

Huey signals

Optionally hueyx pushes all huey signals to the redis pubsub hueyx.huey2.signaling if enabled.

HUEYX_SIGNALS = {
    'enabled': True,
    'environment': 'your environment'
}

The format of the message is

{
    'environment': settings.HUEYX_SIGNALS['environment'],
    'queue': queue,
    'pid': pid,
    'signal': signal_name,
    'task': task_name
}

The environment parameter is a optional variable.

Prometheus

The huey-exporter project takes the signals und reports it to prometheus.

Collaborators

Metadata

Release files for hueyx 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hueyx 1.0.3
File Size Uploaded Provenance Actions
hueyx-1.0.3.tar.gz 14.8 kB Without provenance Details for hueyx-1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hueyx 1.0.3
File Interpreter ABI Platform Actions
hueyx-1.0.3-py3-none-any.whl Python 3 none any Details for hueyx-1.0.3-py3-none-any.whl

Total release size: 32.1 kB

Release files / hueyx-1.0.3.tar.gz

Download URL hueyx-1.0.3.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
896539d876dba483562970c69b40cde92a0679b73f44e8e6650fce304a790290
BLAKE2b-256 checksum
How to use checksums
e07baf2d739e01051da362b4a41d93441c3b89f2a816ec20a167a4a3c8705b9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

Release files / hueyx-1.0.3-py3-none-any.whl

Download URL hueyx-1.0.3-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c37e625fe7bcab2ecc284bb5d35f32331c1d6bb9adc91905b1987994f8d2de8
BLAKE2b-256 checksum
How to use checksums
cf5533006a52de34c7174610a18882e366476f90910548d8fd5dd0ce6baa7eeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

Security for hueyx 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page