-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A better way to check if Rails was run from console #323
Comments
Also when run in an initializer there is no method and therefore it does not return. This also handles multi-process servers such as Puma. So I found this structure to be more useful:
|
Hello,
There is nothing wrong with that, truthy and falsey are good enough and it reads well. Keep your "Yuck" for yourself.
What method are you talking about? May I get a decent issue report? Thanks in advance and best regards. |
Sorry it's not really an issue. Just a minor point with the example code that it uses return but the initializer is not in a method. My main point with is issue is that |
Thanks.
What version of Rails are you using on what version of Ruby? |
Yeah it's possibly version related. I'm using Rails 6.1.4, Ruby 2.6.6. I'll give it a try on a 5.2 app I've as well. |
My mistake. So yeah, in Rails 6
|
Thanks a lot! I will adapt the README to that change. |
Hold on, I'm having trouble with |
I'm at a loss. However, when running in a console the scheduled jobs are not run, I'm guessing because the console is blocking. So it seems a little accidental but has the same effect. There maybe other scenarios where they do run however. |
OK, I will take a look at that during the week-end. Thanks for the information so far! |
Thanks. And thank you for a great tool! |
notes in passing, while playing with a test Rails 6 install |
Hello, I am not a Rails user, but I can find my way around. I think that the Spring tool is what is giving you sketchy result. When Spring is in action, the Rails initializers are run only once (and they stick in the Spring process). You have to run I disabled Spring with Could you please double check that on your side? If that's the case, I'll update the rufus-scheduler README to explain the situation. Thanks in advance. |
Yeah I was doing It also is running when in the console. It wasn't logging to screen but I checked the Rails logger and it's still pumping messages into there when the jobs run. I'm thinking it might not be useful to run in development anyway so I'll probably have a flag you can set to turn it on. Normal behaviour is for people to run Spring and I don't want to force them to do something different. I think a note about Spring would be useful. Thanks so much for looking into this. |
Just to clarify: If you run a console with Spring then exit the console jobs will still run until running |
OK. Yesterday I worked with https://github.com/jmettraux/sc_gh323_rails_console
Once Spring was put aside, all the I cannot reproduce your issue. I will add a note about Spring in the README and then close this issue. |
return if defined?(Rails::Console) || Rails.env.test? || File.split($0).last == 'rake'
didn't work too well for me and is also quite wrong in thatdefined?
returns a string not a boolean. Yuck.After quite a bit of digging I found the Ruby 2.5 class method
const_defined?
to be more suitable.Rails.const_defined?('Console')
did the trick and correctly returned when in an initializer.I hope this helps others.
The text was updated successfully, but these errors were encountered: