zeus 0.10.0 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  {
2
- "command": "ruby -rzeus/rails -eZeus.go",
2
+ "command": "ruby -rubygems -rzeus/rails -eZeus.go",
3
3
 
4
4
  "plan": {
5
5
  "boot": {
@@ -5,63 +5,27 @@ require 'zeus/load_tracking'
5
5
 
6
6
  module Zeus
7
7
  class Plan
8
+ def after_fork ; end
8
9
  end
9
10
 
10
11
  class << self
11
-
12
- def add_extra_feature(path)
13
- $untracked_features ||= []
14
- $untracked_features << path
15
- end
16
-
17
12
  attr_accessor :plan
18
13
 
19
- def report_error_to_master(local, error)
20
- str = "R:"
21
- str << "#{error.backtrace[0]}: #{error.message} (#{error.class})\n"
22
- error.backtrace[1..-1].each do |line|
23
- str << "\tfrom #{line}\n"
24
- end
25
- str << "\0"
26
- local.write str
27
- end
28
-
29
- def run_action(socket, identifier)
30
- plan.send(identifier)
31
- socket.write "R:OK\0"
32
- rescue Exception => e
33
- report_error_to_master(socket, e)
34
- end
35
-
36
- def notify_features(sock, features)
37
- features.each do |t|
38
- begin
39
- sock.write "F:#{t}\0"
40
- rescue Errno::ENOBUFS
41
- sleep 0.2
42
- retry
43
- end
44
- end
45
- end
46
-
47
14
  def go(identifier=:boot)
48
- identifier = identifier.to_sym
49
15
  $0 = "zeus slave: #{identifier}"
50
16
  # okay, so I ahve this FD that I can use to send data to the master.
51
17
  fd = ENV['ZEUS_MASTER_FD'].to_i
52
18
  master = UNIXSocket.for_fd(fd)
53
19
 
54
20
  # I need to give the master a way to talk to me exclusively
55
- local, remote = UNIXSocket.pair(:STREAM)
56
-
21
+ local, remote = UNIXSocket.pair(Socket::SOCK_STREAM)
57
22
  master.send_io(remote)
58
23
 
59
24
  # Now I need to tell the master about my PID and ID
60
- File.open("a.log","a") { |f| f.puts identifier}
61
25
  local.write "P:#{Process.pid}:#{identifier}\0"
62
26
 
63
27
  # Now we run the action and report its success/fail status to the master.
64
- features = features_loaded_by {
28
+ features = Zeus::LoadTracking.features_loaded_by {
65
29
  run_action(local, identifier)
66
30
  }
67
31
 
@@ -72,26 +36,18 @@ module Zeus
72
36
  loop do
73
37
  messages = local.recv(1024)
74
38
  messages.split("\0").each do |new_identifier|
75
- if new_identifier =~ /^S:/
76
- fork { plan.after_fork ; go(new_identifier.sub(/^S:/,'')) }
39
+ new_identifier =~ /^(.):(.*)/
40
+ code, ident = $1, $2
41
+ if code == "S"
42
+ fork { plan.after_fork ; go(ident.to_sym) }
77
43
  else
78
- fork { plan.after_fork ; command(new_identifier.sub(/^C:/,''), local) }
44
+ fork { plan.after_fork ; command(ident.to_sym, local) }
79
45
  end
80
46
  end
81
47
  end
82
48
  end
83
49
 
84
- def all_features
85
- untracked = defined?($untracked_features) ? $untracked_features : []
86
- $LOADED_FEATURES + untracked
87
- end
88
-
89
- def features_loaded_by(&block)
90
- old_features = all_features()
91
- yield
92
- new_features = all_features() - old_features
93
- return new_features
94
- end
50
+ private
95
51
 
96
52
  def command(identifier, sock)
97
53
  $0 = "zeus runner: #{identifier}"
@@ -126,5 +82,33 @@ module Zeus
126
82
  local.close
127
83
  end
128
84
 
85
+ def notify_features(sock, features)
86
+ features.each do |t|
87
+ begin
88
+ sock.write "F:#{t}\0"
89
+ rescue Errno::ENOBUFS
90
+ sleep 0.2
91
+ retry
92
+ end
93
+ end
94
+ end
95
+
96
+ def report_error_to_master(local, error)
97
+ str = "R:"
98
+ str << "#{error.backtrace[0]}: #{error.message} (#{error.class})\n"
99
+ error.backtrace[1..-1].each do |line|
100
+ str << "\tfrom #{line}\n"
101
+ end
102
+ str << "\0"
103
+ local.write str
104
+ end
105
+
106
+ def run_action(socket, identifier)
107
+ plan.send(identifier)
108
+ socket.write "R:OK\0"
109
+ rescue Exception => e
110
+ report_error_to_master(socket, e)
111
+ end
112
+
129
113
  end
130
114
  end
@@ -1,22 +1,37 @@
1
1
  module Zeus
2
- class Server
3
- class LoadTracking
4
- class << self
5
-
6
- def add_feature(file)
7
- path = if File.exist?(File.expand_path(file))
8
- File.expand_path(file)
9
- else
10
- find_in_load_path(file)
11
- end
12
- Zeus.add_extra_feature(path) if path
13
- end
2
+ class LoadTracking
3
+ class << self
14
4
 
15
- private
5
+ def features_loaded_by(&block)
6
+ old_features = all_features()
7
+ yield
8
+ new_features = all_features() - old_features
9
+ return new_features
10
+ end
16
11
 
17
- def find_in_load_path(file)
18
- $LOAD_PATH.map { |path| "#{path}/#{file}" }.detect{ |file| File.exist? file }
12
+ def add_feature(file)
13
+ path = if File.exist?(File.expand_path(file))
14
+ File.expand_path(file)
15
+ else
16
+ find_in_load_path(file)
19
17
  end
18
+ add_extra_feature(path) if path
19
+ end
20
+
21
+ private
22
+
23
+ def all_features
24
+ untracked = defined?($untracked_features) ? $untracked_features : []
25
+ $LOADED_FEATURES + untracked
26
+ end
27
+
28
+ def add_extra_feature(path)
29
+ $untracked_features ||= []
30
+ $untracked_features << path
31
+ end
32
+
33
+ def find_in_load_path(file)
34
+ $LOAD_PATH.map { |path| "#{path}/#{file}" }.detect{ |file| File.exist? file }
20
35
  end
21
36
  end
22
37
  end
@@ -31,7 +46,7 @@ module Kernel
31
46
  class << self
32
47
  alias_method :__load_without_zeus, :load
33
48
  def load(file, *a)
34
- Zeus::Server::LoadTracking.add_feature(file)
49
+ Zeus::LoadTracking.add_feature(file)
35
50
  __load_without_zeus(file, *a)
36
51
  end
37
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-07 00:00:00.000000000 Z
12
+ date: 2012-09-13 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Boot any rails app in under a second
15
15
  email: