Module: Zeus

Defined in:
lib/zeus.rb,
lib/zeus/m.rb,
lib/zeus/plan.rb,
lib/zeus/rails.rb,
lib/zeus/version.rb,
lib/zeus/load_tracking.rb,
lib/zeus/m/test_method.rb,
lib/zeus/m/test_collection.rb

Defined Under Namespace

Modules: M Classes: LoadTracking, Plan, Rails

Constant Summary collapse

VERSION =
"0.13.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dummy_ttyObject

Returns the value of attribute dummy_tty.



12
13
14
# File 'lib/zeus.rb', line 12

def dummy_tty
  @dummy_tty
end

.master_socketObject

Returns the value of attribute master_socket.



12
13
14
# File 'lib/zeus.rb', line 12

def master_socket
  @master_socket
end

.planObject

Returns the value of attribute plan.



12
13
14
# File 'lib/zeus.rb', line 12

def plan
  @plan
end

Class Method Details

.go(identifier = :boot) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/zeus.rb', line 37

def go(identifier=:boot)
  $0 = "zeus slave: #{identifier}"

  setup_dummy_tty!
  master = setup_master_socket!
  feature_pipe_r, feature_pipe_w = IO.pipe

  # I need to give the master a way to talk to me exclusively
  local, remote = UNIXSocket.pair(Socket::SOCK_STREAM)
  master.send_io(remote)

  # Now I need to tell the master about my PID and ID
  local.write "P:#{Process.pid}:#{identifier}\0"
  local.send_io(feature_pipe_r)

  # Now we run the action and report its success/fail status to the master.
  features = Zeus::LoadTracking.features_loaded_by {
    run_action(local, identifier)
  }

  # the master wants to know about the files that running the action caused us to load.
  Thread.new { notify_features(feature_pipe_w, features) }

  # We are now 'connected'. From this point, we may receive requests to fork.
  children = Set.new
  loop do
    messages = local.recv(2**16)

    # Reap any child runners or slaves that might have exited in
    # the meantime. Note that reaping them like this can leave <=1
    # zombie process per slave around while the slave waits for a
    # new command.
    children.each do |pid|
      children.delete(pid) if Process.waitpid(pid, Process::WNOHANG)
    end

    messages.split("\0").each do |new_identifier|
      new_identifier =~ /^(.):(.*)/
      code, ident = $1, $2
      pid = nil
      if code == "S"
        children << fork { go(ident.to_sym) }
      else
        children << fork { command(ident.to_sym, local) }
      end
    end
  end
end

.setup_dummy_tty!Object

this is totally asinine, but readline gets super confused when it’s required at a time when stdin or stdout is not connected to a TTY, no matter what we do to tell it otherwise later. So we create a dummy TTY in case readline is required.

Yup.



20
21
22
23
24
25
26
27
28
# File 'lib/zeus.rb', line 20

def setup_dummy_tty!
  return if self.dummy_tty
  master, self.dummy_tty = PTY.open
  Thread.new {
    loop { master.read(1024) }
  }
  STDIN.reopen(dummy_tty)
  STDOUT.reopen(dummy_tty)
end

.setup_master_socket!Object



30
31
32
33
34
35
# File 'lib/zeus.rb', line 30

def setup_master_socket!
  return master_socket if master_socket

  fd = ENV['ZEUS_MASTER_FD'].to_i
  self.master_socket = UNIXSocket.for_fd(fd)
end