Django rq worker proper setup passing django settngs

864 Views Asked by At

i Have a django project which works fine. I need a rq worker to do a job. I got a redis-server running.

Whis is my worker.py file:

import os

import redis
from rq import Worker, Queue, Connection

listen = ['high', 'default', 'low']

redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')

conn = redis.from_url(redis_url)

if __name__ == '__main__':
    with Connection(conn):
        os.environ['DJANGO_SETTINGS_MODULE']='ak.settings.prod_lt'
        worker = Worker(map(Queue, listen))
        worker.work()

I run the worker from my ubuntu terminal using the following commandline: /opt/crm/env/bin/python /opt/crm/ak/ak/worker.py

The worker starts fine.

The job I am giving it is getting data from the database and writing the data to an excel file but I am getting the following error:

rq.exceptions.UnpickleError: (
    u'Could not unpickle',
    ImportError('No module named ak.settings.prod_lt',
    <function model_unpickle at 0x7fcba6b67938>, 
    (('crm', 'EmailExport'), [], <function simple_class_factory at 0x7fcba6b678c0>)))

Can anybody tell me what could be wrong?

0

There are 0 best solutions below