Best way to not run rufus-scheduler when starting a rails console

血红的双手。 提交于 2019-12-05 07:26:54
Brian Glick

Based on Rails check if IRB console or webpage:

unless self.private_methods.include? 'irb_binding'
  #put your rufus scheduling here
end

I had the same issue when I used rufus-scheduler and delayed-jobs.

I used this:

unless defined?(Rake) || defined?(IRB)
  # your code here
end

Tested in Rails 4

As per the revised documentation for rufus-scheduler here:

If you don't want rufus-scheduler to kick in when running the Ruby on Rails console or invoking a rake task, you can wrap your initializer in a conditional:

unless defined?(Rails::Console) || File.split($0).last == 'rake'
  # your code here
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!