Class: Theine::Worker
- Inherits:
-
Object
- Object
- Theine::Worker
- Defined in:
- lib/theine/worker.rb
Constant Summary collapse
- COMMANDS =
{ rails: proc { require 'rails/commands' }, rake: proc { require 'rake' ::Rails.application.load_tasks if defined? ::Rails tasks = [] ARGV.each do |arg| if arg =~ /^(\w+)=(.*)$/m ENV[$1] = $2 else tasks << arg end end tasks.each do |task| is_test_task = task =~ /^(spec|test)$/ if is_test_task previous_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development" change_rails_env_to("test") end ::Rake::Task[task].invoke change_rails_env_to(previous_env) if is_test_task end }, rspec: proc { change_rails_env_to("test") require 'rspec/core' RSpec::Core::Runner.autorun }, cucumber: proc { change_rails_env_to("test") require 'active_support/descendants_tracker' require 'cucumber/rspec/disable_option_parser' require 'cucumber/cli/main' cucumber_runtime = Cucumber::Runtime.new cucumber_main = Cucumber::Cli::Main.new(ARGV.dup) cucumber_main.execute!(cucumber_runtime) } }
Instance Attribute Summary collapse
-
#balancer ⇒ Object
readonly
Returns the value of attribute balancer.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(port, balancer) ⇒ Worker
constructor
A new instance of Worker.
- #pid ⇒ Object
- #run ⇒ Object
- #screen_attached? ⇒ Boolean
- #screen_move_to_bottom ⇒ Object
- #stop! ⇒ Object
Constructor Details
#initialize(port, balancer) ⇒ Worker
Returns a new instance of Worker.
55 56 57 58 59 |
# File 'lib/theine/worker.rb', line 55 def initialize(port, balancer) @port = port @balancer = balancer @command_proc = proc { } end |
Instance Attribute Details
#balancer ⇒ Object (readonly)
Returns the value of attribute balancer.
7 8 9 |
# File 'lib/theine/worker.rb', line 7 def balancer @balancer end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/theine/worker.rb', line 7 def port @port end |
Instance Method Details
#pid ⇒ Object
82 83 84 |
# File 'lib/theine/worker.rb', line 82 def pid ::Process.pid end |
#run ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/theine/worker.rb', line 61 def run boot begin DRb.thread.join screen_move_to_bottom sleep 0.1 while !screen_attached? puts "command: #{@command_name} #{argv_to_s}" instance_exec(&@command_proc) ensure balancer.worker_done(port) end end |
#screen_attached? ⇒ Boolean
90 91 92 |
# File 'lib/theine/worker.rb', line 90 def screen_attached? !system("screen -ls | grep theine#{@port} | grep Detached > /dev/null") end |
#screen_move_to_bottom ⇒ Object
94 95 96 |
# File 'lib/theine/worker.rb', line 94 def screen_move_to_bottom puts "\033[22B" end |
#stop! ⇒ Object
86 87 88 |
# File 'lib/theine/worker.rb', line 86 def stop! exit(1) end |