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

Passing timeout to queued job #16

Closed
ErikEvenson opened this issue Mar 16, 2013 · 18 comments
Closed

Passing timeout to queued job #16

ErikEvenson opened this issue Mar 16, 2013 · 18 comments

Comments

@ErikEvenson
Copy link

Is it possible to pass a timeout value to an enqueued job? I believe the default is 180 seconds -- which is short for some long-running jobs.

Thanks for the great tool!

@ErikEvenson
Copy link
Author

I've asked about this here: http://stackoverflow.com/questions/15445036/rqworker-timeout

@ErikEvenson
Copy link
Author

It seems what is needed from my very quick perusal of the rq and django-rq code base, is a enqueue_call(...) method in django-rq's queue.py module that parallels rq's queue.py module here: https://github.com/nvie/rq/blob/5a5e14cc70bca19458070665eef753b9b2db78f5/rq/queue.py#L116. Then we could pass a timeout value to rq through django-rq.

@selwin
Copy link
Collaborator

selwin commented Mar 16, 2013

Yes, get_queue will return a Queue instance so you can just do:

queue = get_queue('default')
queue.enqueue(long_running_func, timeout=500)

I'm gonna close this issue, but feel free to open it again if you're having troubles.

@selwin selwin closed this as completed Mar 16, 2013
@ErikEvenson
Copy link
Author

If I do that, timeout=500 is passed to my long_running_func -- not to the rq Queue initialization.

@ErikEvenson
Copy link
Author

I tried this and I think it is working. Thanks for your help.

queue = django_rq.get_queue('default')
queue.default_timeout = 500
queue.enqueue(
    populate_trends, 
    self, 
)

@selwin
Copy link
Collaborator

selwin commented Mar 16, 2013

Sorry for the late reply. Try this:

queue.enqueue(populate_trends, args=[self], timeout=500) 

@ErikEvenson
Copy link
Author

That doens't seem to work. I get an Assertion Error: [<Customer: Customer 2>] is not a valid args list. (self is a Customer object.)

@selwin
Copy link
Collaborator

selwin commented Mar 16, 2013

https://github.com/nvie/rq/blob/5a5e14cc70bca19458070665eef753b9b2db78f5/rq/job.py#L75 enforces args to be a tuple, so this should do the trick:

queue.enqueue(populate_trends, args=(self,), timeout=500) 

@ErikEvenson
Copy link
Author

Yep, that syntax seems to do the trick. Interesting -- thanks again for the help.

@mngmntt
Copy link

mngmntt commented Jun 6, 2013

Hello,

don't you want to make it an argument of @job decorator?

It doesn't really look good when you change something like this encoder.start.delay(video.id) to extra lines with getting a queue and setting a timeout.

I believe we just need to expose this argument and pass it to the get_queue in here:
https://github.com/ui/django-rq/blob/master/django_rq/decorators.py#L23

@freeyoung
Copy link

Agreed with @irqed.

@selwin
Copy link
Collaborator

selwin commented Jan 9, 2014

@irqed @freeyoung you should already be able to pass timeout argument to @job decorator. Is it not working for you?

@mngmntt
Copy link

mngmntt commented Jan 9, 2014

@selwin @freeyoung nope, it didn't in some reason. But as you can see I've made a comment about 7 months ago. Even the link isn't correct anymore. Didn't use it since that project.

@selwin
Copy link
Collaborator

selwin commented Jan 9, 2014

@irqed sorry, I must have missed your comment. I only visited this thread again when Github sent me an email of @freeyoung's comment yesterday.

So it didn't work for you seven months ago, correct? If that's the case, it must have been a bug in RQ back then.

All along, Django RQ has accepted all *args and **kwargs and passing them into RQ's decorator so I don't see why it wouldn't work.

@mngmntt
Copy link

mngmntt commented Jan 9, 2014

@selwin @freeyoung yeah, I see that it should work properly. Sorry but I don't remember how I came up with this conclusion. I can't test it against that codebase anymore, I left the company. But I'll try to test it on the weekend.

@selwin
Copy link
Collaborator

selwin commented Jan 9, 2014

Thanks a lot. Much appreciated :)

Sent from my phone

On Jan 9, 2014, at 5:54 PM, Alexander Shchepetilnikov notifications@github.com wrote:

@selwin @freeyoung yeah, I see that it should work properly. Sorry but I don't remember how I came up with this conclusion. I can't test it against that codebase anymore, I left the company. But I'll try to test it on the weekend.


Reply to this email directly or view it on GitHub.

@ccurvey
Copy link

ccurvey commented May 5, 2020

update for those of you finding this page from a search engine. The timeout parameter is now called job_timeout. So the proper incantation is

queue.enqueue(populate_trends, args=(self,), job_timeout=500) 

@extremoburo
Copy link

extremoburo commented Dec 11, 2020

@ccurvey == saviour

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

6 participants