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

3

6

I use rufus-scheduler to run some periodic tasks, but they are extremely annoying to have in the rails console when I just want to test things. Is there an easy way to stop all rufus-scheduler tasks when starting a console automatically?

In the code that starts the scheduler if i can check that i am just in a rails console I can not run them, or if there is a way to run some callbacks when the console starts I can also shut them down there.

Thanks

Halfcaste answered 4/5, 2011 at 22:23 Comment(0)
I
6

Based on Rails check if IRB console or webpage:

unless self.private_methods.include? 'irb_binding'
  #put your rufus scheduling here
end
Indomitable answered 13/6, 2011 at 17:1 Comment(0)
U
7

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

Uremia answered 17/10, 2013 at 2:48 Comment(0)
I
6

Based on Rails check if IRB console or webpage:

unless self.private_methods.include? 'irb_binding'
  #put your rufus scheduling here
end
Indomitable answered 13/6, 2011 at 17:1 Comment(0)
E
2

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
Eduction answered 3/4, 2017 at 11:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.