I'm trying to use Python-RQ with Zope by calling an external method (for background tasks) from ZMI after a certain operation. The file called by external method resides in Extensions. It initialises connection to Redis and imports a module that runs the background tasks. The question is where should this to be imported file be placed ? Python-RQ does not seem to recognise if I put it inside Products directory. It throws no module named Products.xyz
. Below is the code snippet
from redis import Redis
from rq import Queue
from Products.def_update_company_status import ae_update_company_status
q = Queue(connection=Redis())
def rq_worker(context):
q.enqueue(ae_update_company_status)
return 'DONE'
The rq_worker function is invoked by the external method.
Below is the error
18:12:40 default: Products.def_update_company_status.ae_update_company_status() (4b2b5c81-e329-4031-a3e7-b9b1bb198278)
18:12:40 ImportError: No module named Products.def_update_company_status
Traceback (most recent call last):
File "/home/zope/ams/lib/python2.6/site-packages/rq-0.6.0-py2.6.egg/rq/worker.py", line 588, in perform_job
rv = job.perform()
File "/home/zope/ams/lib/python2.6/site-packages/rq-0.6.0-py2.6.egg/rq/job.py", line 498, in perform
try:
File "/home/zope/ams/lib/python2.6/site-packages/rq-0.6.0-py2.6.egg/rq/job.py", line 206, in func
File "/home/zope/ams/lib/python2.6/site-packages/rq-0.6.0-py2.6.egg/rq/utils.py", line 150, in import_attribute
module = importlib.import_module(module_name)
File "build/bdist.linux-x86_64/egg/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named Products.def_update_company_status
Traceback (most recent call last):
File "/home/zope/ams/lib/python2.6/site-packages/rq-0.6.0-py2.6.egg/rq/worker.py", line 588, in perform_job
rv = job.perform()
File "/home/zope/ams/lib/python2.6/site-packages/rq-0.6.0-py2.6.egg/rq/job.py", line 498, in perform
try:
File "/home/zope/ams/lib/python2.6/site-packages/rq-0.6.0-py2.6.egg/rq/job.py", line 206, in func
File "/home/zope/ams/lib/python2.6/site-packages/rq-0.6.0-py2.6.egg/rq/utils.py", line 150, in import_attribute
module = importlib.import_module(module_name)
File "build/bdist.linux-x86_64/egg/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named Products.def_update_company_status
18:12:40 Moving job to u'failed' queue
18:12:40
18:12:40 *** Listening on default...