We use Sidekiq to process background jobs, such as this:
def process_order(id)
... do something
end
Sidekiq is set to 50-100 threads, so we’ve seen process_order
run on the same id
at the same time, which we don’t want. What is the best way to ensure process_order
do not run on the same id
concurrently?
I looked into https://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Async.html but the example isn’t very clear (for a newbie).
You’re looking for the unique jobs feature. Sidekiq Enterprise has it and there are 3rd party plugins which also provide it.
50-100 threads is way too much. Ruby doesn’t scale well to that many threads.