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 { ::Rails.application.load_tasks if defined? ::Rails ARGV.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 } }
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.
36 37 38 39 40 |
# File 'lib/theine/worker.rb', line 36 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
63 64 65 |
# File 'lib/theine/worker.rb', line 63 def pid ::Process.pid end |
#run ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/theine/worker.rb', line 42 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
71 72 73 |
# File 'lib/theine/worker.rb', line 71 def screen_attached? !system("screen -ls | grep theine#{@port} | grep Detached > /dev/null") end |
#screen_move_to_bottom ⇒ Object
75 76 77 |
# File 'lib/theine/worker.rb', line 75 def screen_move_to_bottom puts "\033[22B" end |
#stop! ⇒ Object
67 68 69 |
# File 'lib/theine/worker.rb', line 67 def stop! exit(1) end |