django-rq configuration and installation in apps.py

682 Views Asked by At

I use django-rq in my Django application. Currently, I install django-rq with pip, then add the following content to mysite/settings.py:

INSTALLED_APPS += 'django_rq'

RQ_QUEUES = {
    'default': {
        'HOST': 'localhost',
        'PORT': 6379,
        'DB': 0,
        'DEFAULT-TIMEOUT': 360,
    }
}

This works well, but I want to distribute my application with an installation process as simple as possible. Is there a way to move the previous content of settings.py to my-app/apps.py or any other file distributed with my application?

Something like

from django.apps import AppConfig
from django.conf import settings

class MyAppConfig(AppConfig):
    name = 'myapp'

    def ready(self):
        settings.INSTALLED_APPS += 'django_rq'
        settings.RQ_QUEUES = {
            'default': {
                'HOST': 'localhost',
                'PORT': 6379,
                'DB': 0,
                'DEFAULT-TIMEOUT': 360,
            }
        }

This obviously won't work and is not recommended by the documentation, but you get the idea.

0

There are 0 best solutions below