Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not resolve a Redis connection #164

Closed
rochacbruno opened this issue Jan 18, 2013 · 8 comments
Closed

Could not resolve a Redis connection #164

rochacbruno opened this issue Jan 18, 2013 · 8 comments

Comments

@rochacbruno
Copy link

I have followed this example: http://python-rq.org/docs/jobs/

The code:

excel_export/views.py

from rq import get_current_job

def export_on_shell(name):
    current_job = get_current_job()
    # do excel xlwt writings

The Django shell

from django_rq import get_queue
from excel_export.views import export_on_shell
q = get_queue('excel_export')
result = q.enqueue_call(export_on_shell, args=('assinaturas_a_vencer',), result_ttl=-1, timeout=6000)

The above task is sent to the worker but if fails

The Traceback

[2013-01-18 02:01] INFO: worker: *** Listening on excel_export...
[2013-01-18 02:02] INFO: worker: excel_export: excel_export.views.export_on_shell('assinaturas_a_vencer') (88257e11-29f1-4f4e-9b6f-f25fd970fd84)
[2013-01-18 02:02] ERROR: horse: NoRedisConnectionException: Could not resolve a Redis connection.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/rq-0.3.3_dev-py2.7.egg/rq/worker.py", line 396, in perform_job
rv = job.perform()
File "/usr/local/lib/python2.7/dist-packages/rq-0.3.3_dev-py2.7.egg/rq/job.py", line 326, in perform
self._result = self.func(_self.args, *_self.kwargs)
File "/vagrant/spring5/src/excel_export/views.py", line 217, in export_on_shell
current_job = get_current_job()
File "/usr/local/lib/python2.7/dist-packages/rq-0.3.3_dev-py2.7.egg/rq/job.py", line 59, in get_current_job
return Job.fetch(job_id)
File "/usr/local/lib/python2.7/dist-packages/rq-0.3.3_dev-py2.7.egg/rq/job.py", line 159, in fetch
job = cls(id, connection=connection)
File "/usr/local/lib/python2.7/dist-packages/rq-0.3.3_dev-py2.7.egg/rq/job.py", line 164, in init
self.connection = resolve_connection(connection)
File "/usr/local/lib/python2.7/dist-packages/rq-0.3.3_dev-py2.7.egg/rq/connections.py", line 64, in resolve_connection
'Could not resolve a Redis connection.')
NoRedisConnectionException: Could not resolve a Redis connection.

[2013-01-18 02:02] DEBUG: horse: Invoking exception handler <bound method Worker.move_to_failed_queue of <rq.worker.Worker object at 0x2f8b510>>
[2013-01-18 02:02] WARNING: horse: Moving job to failed queue.
[2013-01-18 02:02] INFO: worker:
[2013-01-18 02:02] INFO: worker: *** Listening on excel_export...

@selwin
Copy link
Collaborator

selwin commented Jan 18, 2013

@rochacbruno does your code work if you omit get_current_job?

@nvie
Copy link
Collaborator

nvie commented Jan 18, 2013

EDIT: This comment is a mistake, see below. Don't do this.


The example is incorrect, thanks for catching that. I should update it. A working example would be:

from rq import get_current_job, Connection

def export_on_shell(name):
    with Connection():
        current_job = get_current_job()
    # do excel xlwt writings

But this might not make any sense when called inside the worker. I think I should update the semantics of get_current_job().

@rochacbruno
Copy link
Author

Ok! thanks. For this job I needed to go with Celery because of the deadline. But I am looking forward to use rq again and I am available for testing.

@nvie
Copy link
Collaborator

nvie commented Jan 20, 2013

Pardon me, I was wrong. Giving this a second look, the example from the docs should work and my previous comment was a mistake.

Maybe this has something to do with how django_rq sets up the worker stack? The connection stack should be set up when the job executes, so there's no need to add the connection yourself (the worker has done this already).

@selwin
Copy link
Collaborator

selwin commented Jan 20, 2013

It seems like django-rq doesn't call setup_redis like what RQ's own rqworker script does on https://github.com/nvie/rq/blob/master/rq/scripts/rqworker.py#L49 . I'll fix this sometime in the next few days.

@nvie
Copy link
Collaborator

nvie commented Jan 20, 2013

Thanks!

@selwin
Copy link
Collaborator

selwin commented Jan 21, 2013

This should be fixed in rq/django-rq@eb707f7 . @rochacbruno can you try to see if using the latest version of django-rq fixes this problem? If it doesn't, feel free to open an issue https://github.com/ui/django-rq/issues?state=open as it's actually a bug in django-rq.

@nvie
Copy link
Collaborator

nvie commented Jan 23, 2013

Thanks, @selwin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants