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

get_current_job from django_rq #35

Open
ouhouhsami opened this issue Oct 14, 2013 · 9 comments
Open

get_current_job from django_rq #35

ouhouhsami opened this issue Oct 14, 2013 · 9 comments

Comments

@ouhouhsami
Copy link

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,

@selwin
Copy link
Collaborator

selwin commented Oct 15, 2013

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?

@ouhouhsami
Copy link
Author

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()

@selwin
Copy link
Collaborator

selwin commented Oct 16, 2013

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?

@ouhouhsami
Copy link
Author

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,

@selwin
Copy link
Collaborator

selwin commented Oct 16, 2013

Hold on, why would you want to use get_current_job within runserver command?

On Oct 16, 2013, at 2:04 PM, samuel goldszmidt notifications@github.com 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.

@ouhouhsami
Copy link
Author

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 ?

@selwin
Copy link
Collaborator

selwin commented Oct 16, 2013

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 notifications@github.com 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.

@ouhouhsami
Copy link
Author

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 : rq/rq#269

@selwin
Copy link
Collaborator

selwin commented Oct 16, 2013

It's not currently possible to ask workers about the job they're working on. You're right in that rq/rq#269 is what you'll need. I think it's a reasonable feature request :)

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

2 participants