-
Notifications
You must be signed in to change notification settings - Fork 900
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
Don't use rails runner to launch scripts, require config/environment #4307
Don't use rails runner to launch scripts, require config/environment #4307
Conversation
runner = File.join(rr, "bin/rails runner") | ||
program = File.join(rr, "lib/workers/bin/evm_server.rb") | ||
command_line = "#{runner} #{program}" | ||
command_line = "#{Gem.ruby} #{Rails.root.join("lib/workers/bin/evm_server.rb").expand_path}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array plz
@@ -1,3 +1,5 @@ | |||
require File.expand_path("../../../config/environment", __dir__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay!
<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush. |
75907c8
to
b2fdb51
Compare
The primary use cases for rails runner are for * quick in-line ruby evaluation such as `rails runner 'puts User.first.name'` * shebang line at the top of executables While it supports passing the path to a ruby script, it leads to weird errors if the file is not found for any reason: `$ bin/rails r "/home/joe/run.rb"` => `unknown regexp option - j (SyntaxError)` `$ bin/rails r "joe/run.rb"` => `undefined local variable or method `joe' for main:Object (NameError)` Since this is NOT the typical use case for rails runner, it's safer to use ruby to load our launcher and require config/environment in the launcher. A nice side effect is $PROGRAM_NAME can be reliably used to detect what type of worker the current process is: `manageiq/lib/workers/bin/evm_server.rb`
b2fdb51
to
cfa3603
Compare
Checked commit jrafanie@cfa3603 with ruby 2.2.3, rubocop 0.34.2, and haml-lint 0.13.0 |
@miq-bot rm_label wip |
require "workers/evm_server" | ||
EvmServer.start(*ARGV) | ||
else | ||
puts "run with rails runner evm_server.rb" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewd I removed the lies 👆
👍 can't wait till it turns green |
@matthewd Please review 🍰 |
…h_scripts Don't use rails runner to launch scripts, require config/environment
👏 |
Yay! Great work mr lj |
Yay, thanks!!! 🎉 |
Benefits: * rails runner is for shebang lines or inline ruby, see ManageIQ#4307 * We don't have to check if rails is loaded. * Can be run outside rails root directory via ruby. * We don't need -- to avoid rails runner modifying our args. * Less typing. * Existing bin/rails runner callers with args just work: `ruby tools/purge_orphaned_tag_values.rb -s 100` Or, the old way: `bin/rails runner tools/purge_orphaned_tag_values.rb -- -s 100` Discovered while reviewing: ManageIQ#11281
This will require a bit more work to get the workers to launch properly and to ensure theMiqEnvironment::Process.is_*?
methods can understand workers and the server no longer launching via rails runner.Update: MiqEnvironment::Process is gone 🎉 , see #3593
The primary use cases for rails runner are for
rails runner 'puts User.first.name'
While it supports passing the path to a ruby script, it leads to weird
errors if the file is not found for any reason:
$ bin/rails r "/home/joe/run.rb"
=>
unknown regexp option - j (SyntaxError)
$ bin/rails r "joe/run.rb"
=>
undefined local variable or method
joe' for main:Object (NameError)`Since this is NOT the typical use case for rails runner, it's safer to
use ruby to load our launcher and require config/environment in the
launcher.
A nice side effect is $PROGRAM_NAME can be reliably used to detect what
type of worker the current process is:
manageiq/lib/workers/bin/evm_server.rb