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 ARGV.each do |task| ::Rake::Task[task].invoke end }, rspec: proc { 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.
25 26 27 28 29 |
# File 'lib/theine/worker.rb', line 25 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
52 53 54 |
# File 'lib/theine/worker.rb', line 52 def pid ::Process.pid end |
#run ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/theine/worker.rb', line 31 def run boot begin DRb.thread.join screen_move_to_bottom sleep 0.1 while !screen_attached? puts "command: #{@command_name} #{argv_to_s}" @command_proc.call ensure balancer.worker_done(port) end end |
#screen_attached? ⇒ Boolean
60 61 62 |
# File 'lib/theine/worker.rb', line 60 def screen_attached? !system("screen -ls | grep theine#{@port} | grep Detached > /dev/null") end |
#screen_move_to_bottom ⇒ Object
64 65 66 |
# File 'lib/theine/worker.rb', line 64 def screen_move_to_bottom puts "\033[22B" end |
#stop! ⇒ Object
56 57 58 |
# File 'lib/theine/worker.rb', line 56 def stop! exit(1) end |