I'm running a Sinatra app on Heroku that's using Thin, Ruby 2.0.0. Every 16 hours or so I get this error in the logs and everything inside my rufus-scheduler schedule block stops being run.
Any ideas on what's going wrong?
70217056739720 Rufus::Scheduler::EveryJob "5m" {}
70217056739720 70217056739720
70217056739720 ThreadError
70217056739720 can't create Thread (11)
{ 70217056739720 rufus-scheduler intercepted an error:
70217056739720 job:
70217056739720 error:
70217056739720 /app/lib/pusher_benchmarker.rb:26:in `initialize'
70217056739720 /app/lib/services_runner.rb:13:in `new'
70217056739720 /app/vendor/bundle/ruby/2.0.0/gems/pusher-client-0.4.0/lib/pusher-client/socket.rb:62:in `initialize'
70217056739720 /app/vendor/bundle/ruby/2.0.0/gems/pusher-client-0.4.0/lib/pusher-client/socket.rb:62:in `connect'
70217056739720 /app/lib/services_runner.rb:9:in `initialize'
70217056739720 /app/vendor/bundle/ruby/2.0.0/gems/pusher-client-0.4.0/lib/pusher-client/socket.rb:62:in `new'
70217056739720 /app/lib/pusher_benchmarker.rb:34:in `connect'
70217056739720 /app/vendor/bundle/ruby/2.0.0/gems/rufus-scheduler-3.0.6/lib/rufus/scheduler/jobs.rb:288:in `block (2 levels) in start_work_thread'
70217056739720 /app/vendor/bundle/ruby/2.0.0/gems/rufus-scheduler-3.0.6/lib/rufus/scheduler/jobs.rb:285:in `block (3 levels) in start_work_thread'
70217056739720 /app/vendor/bundle/ruby/2.0.0/gems/rufus-scheduler-3.0.6/lib/rufus/scheduler/jobs.rb:288:in `call'
70217056739720 /app/app.rb:46:in `new'
70217056739720 /app/app.rb:46:in `block (2 levels) in <class:BenchmarkAnalysis>'
70217056739720 /app/vendor/bundle/ruby/2.0.0/gems/rufus-scheduler-3.0.6/lib/rufus/scheduler/jobs.rb:224:in `call'
70217056739720 /app/vendor/bundle/ruby/2.0.0/gems/rufus-scheduler-3.0.6/lib/rufus/scheduler/jobs.rb:224:in `do_call'
70217056739720 /app/vendor/bundle/ruby/2.0.0/gems/rufus-scheduler-3.0.6/lib/rufus/scheduler/jobs.rb:248:in `do_trigger'
70217056739720 /app/lib/services_runner.rb:13:in `initialize_services'
} 70217056739720 .
70217056739720 /app/vendor/bundle/ruby/2.0.0/gems/rufus-scheduler-3.0.6/lib/rufus/scheduler/jobs.rb:274:in `loop'
70217056739720 /app/vendor/bundle/ruby/2.0.0/gems/rufus-scheduler-3.0.6/lib/rufus/scheduler/jobs.rb:274:in `block in start_work_thread'
So if Heroku limits the number of threads, I'd limit the work threads in rufus-scheduler.
https://github.com/jmettraux/rufus-scheduler/#max_work_threads
You could tune that when instantiating the scheduler, like in:
scheduler = Rufus::Scheduler.new(:max_work_threads => 7)
By default max_work_threads is 28.