Search code examples
rubymultithreadingrufus-scheduler

Rufus Scheduler blocks after how many threads?


Writing a scheduler in rufus where the scheduled tasks will overlap. This is expected behavior, but was curious how rufus handles the overlap. Will it overlap up to n threads and then block from there? Or does it continue to overlap without a care of how many concurrent tasks run at a time.

Ideally I would like to take advantage of rufus concurrency and not have to manage my own pool of managed threads. Would like to block once I've reached the max pool count.

scheduler = Rufus::Scheduler.new

# Syncs one tenant in every call. Overlapping calls will allow for multiple
# syncs to occur until all threads expended, then blocks until a thread is available.
scheduler.every '30s', SingleTenantSyncHandler 

Edit Seeing from the README that rufus does use thread pools in version 3.x. You can set the max thread count like:

scheduler = Rufus::Scheduler.new(:max_work_threads => 77)

Assuming this answers my question but still would like confirmation from others.


Solution

  • Yes, I confirm, https://github.com/jmettraux/rufus-scheduler/#max_work_threads answers your question. Note that this thread pool is shared among all scheduled jobs in the rufus-scheduler instance.