django-rq
django-rq copied to clipboard
get_current_job from django_rq
Hi,
I'm trying to use get_current_job() function from rq , but I can't figure how to do this.
import rq
rq.get_current_job() # return None
I'm using django_rq, and think it's a problem of connection ?
When looking a code in rq/jobs.py, we see it uses LocalStack, and it seems that LocalStack is not 'aware' of our redis connection, as mentioned in django_rq rqworker command.
Cheers,
We used to have a problem where jobs with "get_current_job" would fail , but not ever since we added this line here: https://github.com/ui/django-rq/blob/master/django_rq/management/commands/rqworker.py#L69
Are you getting any errors?
No, I don't get errors, I just get None returned by the get_current_job when I call it from outside the management command, even if there are current job in progress (not in queue, but job which is actually in progress). So, as you mention, I don't know how I can push the redis connection inside LocalStack in django views.
I tried
import rq
rq.get_current_job() # return None
I think I should use something like from an API point of view.
import django_rq
django_rq.get_current_job()
Sorry I wasn't being entirely clear. What I meant is that we already push the Redis connection into LocalStack when you run python manage.py rqworker.
get_current_job should just work. Are you running into these issues when during tests or in production? Could you perhaps provide a failing test case for this issue?
Thx for your answer.
Well, I understood what you have done, but I think it's only working inside the scope of rqworker management command. In my use case, I need to access the get_current_job "from inside" the runserver command, which is an other process. I try to write the test !.
Cheers,
Hold on, why would you want to use get_current_job within runserver command?
On Oct 16, 2013, at 2:04 PM, samuel goldszmidt [email protected] wrote:
Thx for your answer.
Well, I understood what you have done, but I think it's only working inside the scope of rqworker management command. In my use case, I need to access the get_current_job "from inside" the runserver command, which is an other process. I try to write the test !.
Cheers,
— Reply to this email directly or view it on GitHub.
I want to be able to get the current job in progress (not the enqueued ones). I have got a django app that allows users to launch jobs, and I want to inform them about the state of these jobs : if it's "in progress", "failed" or "enqueued". May be my approach seems wrong to you ?
It won't work because under runserver, that function would just be a regular function and not a job (get_current_job would always return None).
What you can do is to get the job id of the resultant job and query RQ for the status of the job from within Django.
On Oct 16, 2013, at 2:20 PM, samuel goldszmidt [email protected] wrote:
I want to be able to get the current job in progress (not en enqueued ones). I have got a django app that allow user to launch jobs, and I want to inform them about the state of theirs job : if it's in progress, failed, or enqueued. May be my approach seems wrong to you ?
— Reply to this email directly or view it on GitHub.
Ok, I just need helping hand to for the way to 'ask' workers about the job they are working on. I have:
import django_rq
worker = django_rq.get_worker('default')
I can get worker.state, but not the current_job is working on. Is this the way to do it ? Because I don't thing it's a good approach to keep job ids from the place I have enqueued them, as this information should be somewhere on the redis.
Also, I need to take a look at this : https://github.com/nvie/rq/pull/269
It's not currently possible to ask workers about the job they're working on. You're right in that nvie/rq#269 is what you'll need. I think it's a reasonable feature request :)