Run job multiple times, but never at the same time
wuarmin opened this issue · comments
Hey!
Thanks for this great gem! One question:
I want a job to run multiple times in a row, but never at the same time, no matter how long it takes.
I.e. I tried following
:scheduler:
:schedule:
test:
interval: '1m' # interval one minute
class: Bookshelf::Jobs::Test
but Bookshelf::Jobs::Test sleeps for 115
secs
module Bookshelf
module Jobs
class Test < PayNRed::Job
def perform
# simulate a long-running job
sleep 115
end
end
end
end
but with this the result are 2 busy jobs. Is it possible to specify that a job is not called if the old one is still running?
thanks and best regards
We don't have this feature. Maybe you can check out https://github.com/mhenrixon/sidekiq-unique-jobs
I know sidekiq enterprise also has kind of a similar feature, which is Sidekiq Limiter, but that requires paying for sidekiq enterprise https://github.com/sidekiq/sidekiq/wiki/Ent-Rate-Limiting
@marcelolx Thanks for the response. Ok, then I will do it in user-land.
module Bookshelf
module Jobs
class Test < PayNRed::Job
def perform
return if old_job_is_still_running?
# simulate a long-running job
sleep 115
end
end
end
end
Yes, that works if you record somewhere if the job is already running. Not sure how you're going to implement old_job_is_still_running?
, assuming it is a flag in redis, keep in mind that if the job fails you want to set the key in redis to false otherwise, if a job fails no other job would run since it would continue to return true
even though there isn't a job running.