jmettraux/rufus-scheduler

Best practice use of Thread

darlandieterich opened this issue · 7 comments

I have a question regarding the use of rufus-scheduler. I'm calling a script (method in module) every 1 minute inside a Thread.new, so my question is will I have any future problems with my application by getting heavy creating a Thread every minute? and also it is closed after use?

s = Rufus::Scheduler.singleton
s.every '1m'
     puts "====== Email ======="
     Thread.new
         Checker.check_mail
     end
end

thanks

Hello,

rufus-scheduler has a pool of work threads, you don't need to wrap the work code in a new thread, you can simply write:

Rufus::Scheduler.singleton.every '1m' do
  Checker.check_mail
end

You can set the max work thread count with max_work_threads: (see https://github.com/jmettraux/rufus-scheduler#max_work_threads)

If you fear overlap, you can use blocking:, overlap:, or mutex: to get more control.

Best regards.

Hello @jmettraux !
The rufus is awesome!
Ok, but in my case, I have two 'checkers' 1 every 1 minutes and other every 2 minutes, the ideal 'max_work_threads' is 2?

Sorry for my question fool..
I can use the Issues for question?

very Thanks!
greetings

Hello,

I'd suggest letting max_work_threads: to its default value (28) for now and see how it turns out.

Yes, you can use the issues for asking questions. Please close the issue once you've determined the question in answered.

Best regards.

I have more only one question :)
Can the application (Rails API) hang while it is processing the schedule?
because it is constantly being requested ..

thanks

It should be OK. Rufus-scheduler uses threads (as said above). Rails uses threads or forked processes but that depends on the server library you're using it on top of (Thin, Unicorn, Passenger, Puma, ...). Each of those servers has its advantages and disadvantages.

very thanks dude!

You're welcome.