Skip to content

A dispatcher that allows using huey with multiple django applications

License

Notifications You must be signed in to change notification settings

InvGate/huey-multitenant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Huey Multitenant - A dispatcher that allows using huey with multiple django applications

I used this project with:

  • Python 2.7.10, Python 3.6.5
  • Redis 3.2.9,
  • Django 1.11.8 apps
  • Huey >= 1.10.0

First, create a virtualenv and install the requirements.

$ pip install -r requirements.txt

Point to some Django instances in config folder, copy default config file and modify it:

$ cp conf/default conf/instance-name.conf

In the django instances you must add djhuey_multitenant app into INSTALLED_APPS. Also replace the huey periodic decorator with the mutitenant decorator

Replace

from huey.contrib.djhuey import periodic_task

@periodic_task(crontab(minute='0', hour='3'))
def nightly_backup():
    sync_all_data()

With

from huey_multitenant.contrib.djhuey_multitenant import PeriodicTask

@PeriodicTask(minute='0', hour='3')
def nightly_backup():
    sync_all_data()

Activate virtualenv and launch the dispatcher:

$ python dispatcherctl.py --consumers 4 --periodic true --verbose true

This will create a schedule.info file inside each django instance with peridic tasks information and run the dispatcher.

How to release

To release just:

  1. Update the version on huey_multitenant/__init__.py
  2. Run python setup.py bdist_wheel --universal
  3. Use the generated .whl file under dist/ on your project.

Examples

To run the examples make sure that the redis server is up.

Install Django.

Create a symbolic link inside your virtualenv site-packages to the huey_multitenant folder. The current version of huey_multitenant can also be installed using python setup.py install.

Create django1.conf file inside bin/conf folder with this content (replace PATH):

[django1]
python=PATH/.venv/bin/python
script=PATH/examples/django_1/manage.py
worker-type=thread
workers=1

Create django2.conf file inside bin/conf folder with this content (replace PATH):

[django2]
python=PATH/.venv/bin/python
script=PATH/examples/django_2/manage.py
worker-type=thread
workers=1

Launch the dispatcher in a terminal

$ python dispatcherctl.py --consumers 4 --periodic true --verbose true

In other terminal go to the examples/django_N folder and run

$ python manage.py shell

Now put some tasks in queue

from django_N.test_app.tasks import long_task
long_task()

About

A dispatcher that allows using huey with multiple django applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages