rq / rq-scheduler

A lightweight library that adds job scheduling capabilities to RQ (Redis Queue)
MIT License
1.45k stars 229 forks source link

Lock can timeout when enqueue_jobs() execution is longer than expected #229

Open marcinn opened 4 years ago

marcinn commented 4 years ago

Hi.

It is possible that scheduler's lock can timeout when enqueue_jobs() execution takes longer than _interval + 10 secs. I'm using interval=5, so max time for enqueue_jobs() is 15 secs. This is too low for long jobs table or connection/server slowdowns. When lock is releasing due to timeout, the other instances of rq-scheduler are acquiring a new lock and do their job in parallel.

The one of the possible solution is to use https://github.com/ionelmc/python-redis-lock with autorenewal=True to acquire a lock, which will be renewed during long call by separate thread.

selwin commented 4 years ago

Yeah, this can be problematic if the scheduler is running on a low interval. I think we can easily avoid this by choosing a mininum lock interval of 60. Mind opening a PR for this?