Package: django-huey
django-hueyThis package is an extension ofhueycontrib djhuey package that allows users to manage multiple queues.Compatible versionsPackageVersionDjango5.0Django4.2Django3.2huey2.5huey2.4InstallationUsing pip package manager run:pip install django-hueyThen, in yoursettings.pyfile add django_huey to the INSTALLED_APPS:INSTALLED_APPS=[...'django_huey',]ConfigurationInsettings.pyyou 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 filesnew in 1.1.0You can also include a queue configuration from another file, located in one of your apps.
Use django_huey.utils.include to do so:Insettings.pyyou may have:DJANGO_HUEY={'default':'first',#this name must match with any of the queues defined below.'queues':{# Your current queues definitions}}# This is newfromdjango_huey.utilsimportincludeDJANGO_HUEY["queues"].update(include("example_app.queues"))And in yourexample_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 calledqueues, so they can be included. If the variable doesn't exist, anAttributeErrorwill be raised.UsageNow you will be able to run multiple queues using:python manage.py djangohuey --queue first
python manage.py djangohuey --queue emailsEach queue must be run in a different terminal.If you defined a default queue, you can just run:python manage.py djangohueyAnd the default queue will be used.Configuring tasksYou can use usualhueydecorators to register tasks, but they must be imported from django_huey as shown below:fromdjango_hueyimportdb_task,task@task()#Use the default queue 'first'defsome_func_that_uses_default_queue():# perform some db taskpass@db_task(queue='first')defsome_func():# perform some db taskpass@task(queue='emails')defsend_mails():# send some emailspassAll the args and kwargs defined in huey decorators should work in the same way, if not, let us know.Importing a huey instanceSometimes 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:fromdjango_hueyimportget_queuefirst_q=get_queue('first')@first_q.task()defsome_func():passIntegration with huey monitorYou can use django-huey withhuey monitorusing the following pattern:fromdjango_hueyimporttask,on_startup,signalfromhuey_monitor.tasksimportstartup_handler,store_signals# This setup must be done for each queue.signal(queue='emails')(store_signals)on_startup(queue='emails')(startup_handler)@task(queue='emails')defsend_mails(parameter):# send some emailspass