Skip to content
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

Merged

Conversation

jrafanie
Copy link
Member

This will require a bit more work to get the workers to launch properly and to ensure the MiqEnvironment::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

  • 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 methodjoe' 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

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}"
Copy link
Contributor

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__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay!

@miq-bot
Copy link
Member

miq-bot commented Dec 23, 2015

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@jrafanie jrafanie force-pushed the dont_use_rails_runner_to_launch_scripts branch from 75907c8 to b2fdb51 Compare January 22, 2016 20:09
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`
@jrafanie jrafanie force-pushed the dont_use_rails_runner_to_launch_scripts branch from b2fdb51 to cfa3603 Compare January 22, 2016 20:24
@miq-bot
Copy link
Member

miq-bot commented Jan 22, 2016

Checked commit jrafanie@cfa3603 with ruby 2.2.3, rubocop 0.34.2, and haml-lint 0.13.0
2 files checked, 0 offenses detected
Everything looks good. 🍪

@jrafanie jrafanie changed the title [WIP] Don't use rails runner to launch scripts, require config/environment Don't use rails runner to launch scripts, require config/environment Jan 22, 2016
@jrafanie
Copy link
Member Author

@miq-bot rm_label wip

@miq-bot miq-bot removed the wip label Jan 22, 2016
require "workers/evm_server"
EvmServer.start(*ARGV)
else
puts "run with rails runner evm_server.rb"
Copy link
Member Author

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 👆

@jrafanie
Copy link
Member Author

Ok, this is ready for review/merge @kbrock @Fryguy @matthewd.

I hope @matthewd approves since I know how much he loves using rails runner with a file :trollface:

@kbrock
Copy link
Member

kbrock commented Jan 22, 2016

👍 can't wait till it turns green

@jrafanie
Copy link
Member Author

@matthewd Please review 🍰

matthewd added a commit that referenced this pull request Jan 27, 2016
…h_scripts

Don't use rails runner to launch scripts, require config/environment
@matthewd matthewd merged commit 0f3cbe1 into ManageIQ:master Jan 27, 2016
@matthewd matthewd added this to the Sprint 36 Ending Feb 16, 2016 milestone Jan 27, 2016
@chrisarcand
Copy link
Member

👏

@kbrock
Copy link
Member

kbrock commented Jan 27, 2016

Yay! Great work mr lj

@jrafanie jrafanie deleted the dont_use_rails_runner_to_launch_scripts branch January 27, 2016 14:35
@jrafanie
Copy link
Member Author

Yay, thanks!!! 🎉

jrafanie added a commit to jrafanie/manageiq that referenced this pull request Sep 20, 2016
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants