Class: Specjour::Manager
- Inherits:
-
Object
- Object
- Specjour::Manager
- Includes:
- DRbUndumped, SocketHelpers
- Defined in:
- lib/specjour/manager.rb
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
-
#bonjour_service ⇒ Object
readonly
Returns the value of attribute bonjour_service.
-
#dispatcher_uri ⇒ Object
Returns the value of attribute dispatcher_uri.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#registered_projects ⇒ Object
readonly
Returns the value of attribute registered_projects.
-
#specs_to_run ⇒ Object
Returns the value of attribute specs_to_run.
-
#worker_pids ⇒ Object
readonly
Returns the value of attribute worker_pids.
-
#worker_size ⇒ Object
readonly
Returns the value of attribute worker_size.
Instance Method Summary collapse
- #available_for?(project_name) ⇒ Boolean
- #bundle_install ⇒ Object
- #dispatch ⇒ Object
- #dispatch_workers ⇒ Object
- #drb_start ⇒ Object
-
#initialize(options = {}) ⇒ Manager
constructor
A new instance of Manager.
- #kill_worker_processes ⇒ Object
- #project_path ⇒ Object
- #start ⇒ Object
- #sync ⇒ Object
Methods included from SocketHelpers
Constructor Details
#initialize(options = {}) ⇒ Manager
Returns a new instance of Manager.
10 11 12 13 14 15 |
# File 'lib/specjour/manager.rb', line 10 def initialize( = {}) @worker_size = [:worker_size] @batch_size = [:batch_size] @registered_projects = [:registered_projects] @worker_pids = [] end |
Instance Attribute Details
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
8 9 10 |
# File 'lib/specjour/manager.rb', line 8 def batch_size @batch_size end |
#bonjour_service ⇒ Object (readonly)
Returns the value of attribute bonjour_service.
8 9 10 |
# File 'lib/specjour/manager.rb', line 8 def bonjour_service @bonjour_service end |
#dispatcher_uri ⇒ Object
Returns the value of attribute dispatcher_uri.
8 9 10 |
# File 'lib/specjour/manager.rb', line 8 def dispatcher_uri @dispatcher_uri end |
#project_name ⇒ Object
Returns the value of attribute project_name.
7 8 9 |
# File 'lib/specjour/manager.rb', line 7 def project_name @project_name end |
#registered_projects ⇒ Object (readonly)
Returns the value of attribute registered_projects.
8 9 10 |
# File 'lib/specjour/manager.rb', line 8 def registered_projects @registered_projects end |
#specs_to_run ⇒ Object
Returns the value of attribute specs_to_run.
7 8 9 |
# File 'lib/specjour/manager.rb', line 7 def specs_to_run @specs_to_run end |
#worker_pids ⇒ Object (readonly)
Returns the value of attribute worker_pids.
8 9 10 |
# File 'lib/specjour/manager.rb', line 8 def worker_pids @worker_pids end |
#worker_size ⇒ Object (readonly)
Returns the value of attribute worker_size.
8 9 10 |
# File 'lib/specjour/manager.rb', line 8 def worker_size @worker_size end |
Instance Method Details
#available_for?(project_name) ⇒ Boolean
17 18 19 |
# File 'lib/specjour/manager.rb', line 17 def available_for?(project_name) registered_projects ? registered_projects.include?(project_name) : true end |
#bundle_install ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/specjour/manager.rb', line 21 def bundle_install Dir.chdir(project_path) do unless system('bundle check > /dev/null') system("bundle install --relock > /dev/null") end end end |
#dispatch ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/specjour/manager.rb', line 42 def dispatch suspend_bonjour do sync bundle_install dispatch_workers end end |
#dispatch_workers ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/specjour/manager.rb', line 50 def dispatch_workers GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=) (1..worker_size).each do |index| worker_pids << fork do exec("specjour --batch-size #{batch_size} #{'--log' if Specjour.log?} --do-work #{project_path},#{dispatcher_uri},#{index}") Kernel.exit! end end at_exit { kill_worker_processes } Process.waitall end |
#drb_start ⇒ Object
70 71 72 73 74 |
# File 'lib/specjour/manager.rb', line 70 def drb_start DRb.start_service nil, self puts "Manager started at #{drb_uri}" at_exit { DRb.stop_service } end |
#kill_worker_processes ⇒ Object
34 35 36 |
# File 'lib/specjour/manager.rb', line 34 def kill_worker_processes Process.kill('TERM', *worker_pids) rescue nil end |
#project_path ⇒ Object
38 39 40 |
# File 'lib/specjour/manager.rb', line 38 def project_path File.join("/tmp", project_name) end |
#start ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/specjour/manager.rb', line 62 def start drb_start puts "Workers ready: #{worker_size}" bonjour_announce Signal.trap('INT') { puts; puts "Shutting down manager..."; exit } DRb.thread.join end |
#sync ⇒ Object
76 77 78 |
# File 'lib/specjour/manager.rb', line 76 def sync cmd "rsync -aL --delete --port=8989 #{dispatcher_uri.host}::#{project_name} #{project_path}" end |