Sha256: 26179560d2c5897ffb722b1f17776f782cadc4c90c4d36c82000f2508bb45688

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

module Specjour
  class Manager
    require 'dnssd'
    include DRbUndumped

    attr_accessor :project_name, :specs_to_run, :dispatcher_uri, :worker_size, :bonjour_service, :batch_size

    def initialize(worker_size = 1, batch_size = 25)
      @worker_size = worker_size
      @batch_size = 25
    end

    def project_path=(name)
      @project_path = name
    end

    def project_path
      @project_path ||= File.join("/tmp", project_name)
    end

    def dispatch
      bonjour_service.stop
      pids = []
      (1..worker_size).each do |index|
        pids << fork do
          exec("specjour --batch-size #{batch_size} --do-work #{project_path},#{dispatcher_uri},#{index},#{specs_to_run[index - 1].join(',')}")
          Kernel.exit!
        end
      end
      at_exit { Process.kill('KILL', *pids) rescue nil }
      Process.waitall
      bonjour_announce
    end

    def start
      drb_start
      bonjour_announce
      Signal.trap('INT') { puts; puts "Shutting down manager..."; exit }
      DRb.thread.join
    end

    def drb_start
      DRb.start_service nil, self
      Kernel.puts "Manager started at #{drb_uri}"
      at_exit { DRb.stop_service }
    end

    def sync
      cmd "rsync -a --port=8989 #{dispatcher_uri.host}::#{project_name} #{project_path}"
    end

    protected

    def cmd(command)
      Kernel.puts command
      system command
    end

    def drb_uri
      @drb_uri ||= URI.parse(DRb.uri)
    end

    def bonjour_announce
      @bonjour_service = DNSSD.register! "specjour_manager_#{object_id}", "_#{drb_uri.scheme}._tcp", nil, drb_uri.port
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
specjour-0.1.2 lib/specjour/manager.rb
specjour-0.1.1 lib/specjour/manager.rb