smith 0.6.5 → 0.6.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac31055456f72df45ea622260b0ca64f4827e4f4
4
- data.tar.gz: 10121bb12dabdfad2bcd635c0f18ff8de26f305b
3
+ metadata.gz: 15e19b548b13abaa3401c8f90ac764f02d55d0e3
4
+ data.tar.gz: dd521bbdd079d43906581c451eabc27b6734d0a2
5
5
  SHA512:
6
- metadata.gz: 7bc73bc698ffc76b75ba3a92715728216dc53eeb34cfca95693234f86cd693f799f6cebe2fc9ab74926351e88513ee22f4efd5fcac49c4497388f0f87a67b4de
7
- data.tar.gz: 6fa9ee4e078d7c9c82879adef1ef4956820e79f160ec12d0cd92e27190a77d0b3f4d0df08e81fbcc462919236f7047b99b0cc168ea9f8effddf06eebf655b3d6
6
+ metadata.gz: 08947494f7f7c93c667a47b3649d9745fc92105441838950f3ca614becd7dfe53696ecc4623d573c93642e30a6005aa765308466727cfe90b299ea6419223454
7
+ data.tar.gz: a279693c851d0cbf971a656c967afff5ac65fce1b3657294a947a74df6c3c20aa20bef5aed4624426a3578dd6fffb2f574558a0127d3d0e5b113edc1b4ca8a35
data/lib/smith/agent.rb CHANGED
@@ -15,8 +15,7 @@ module Smith
15
15
 
16
16
  @factory = QueueFactory.new
17
17
 
18
- @signal_handlers = Hash.new { |h,k| h[k] = Array.new }
19
-
18
+ setup_signal_handlers
20
19
  setup_control_queue
21
20
 
22
21
  @start_time = Time.now
@@ -73,14 +72,46 @@ module Smith
73
72
  raise ArgumentError, "You must override this method"
74
73
  end
75
74
 
75
+ # Set up the mechanics required to implement the self pipe trick.
76
+ def setup_signal_handlers
77
+ @signal_handlers = Hash.new { |h,k| h[k] = Array.new }
78
+ @signal_handler_queue = []
79
+ @signal_handler_pipe_reader, @signal_handler_pipe_writer = IO.pipe
80
+
81
+ # The Module declaration here will only close over local variables so we
82
+ # need to assign self to a local variable to get access to the agent itself.
83
+ agent = self
84
+
85
+ EM.attach(@signal_handler_pipe_reader, Module.new {
86
+ define_method :receive_data do |_|
87
+
88
+ handlers = agent.instance_variable_get(:@signal_handlers)
89
+ queue = agent.instance_variable_get(:@signal_handler_queue)
90
+ signal = queue.pop
91
+
92
+ agent.send(:logger).debug { "Running signal handlers for agent: #{agent.name}: #{signal}" }
93
+ handlers[signal].each { |handler| handler.call(signal) }
94
+ end
95
+ })
96
+ end
97
+
98
+ # Adds a signal handler proc to the list of signal_handlers. When
99
+ # a signal is received all signal handlers are called in reverse order.
100
+ # @param signal [Integer] the signal number.
101
+ # @param position [Symbol] [:first|:last] where on the signal handler stack
102
+ # to put the handler proc.
103
+ # @see Signal.list for a full list of available signals on a system.
76
104
  def install_signal_handler(signal, position=:end, &blk)
77
105
  raise ArgumentError, "Unknown position: #{position}" if ![:beginning, :end].include?(position)
106
+ logger.debug { "Installing signal handler for #{signal}" }
78
107
 
79
- logger.verbose { "Installing signal handler for #{signal}" }
80
108
  @signal_handlers[signal].insert((position == :beginning) ? 0 : -1, blk)
81
- @signal_handlers.each do |sig, handlers|
82
- trap(sig, proc { |sig| run_signal_handlers(sig, handlers) })
83
- end
109
+
110
+ Signal.trap(signal) {
111
+ logger.debug { "Got signal: #{signal}" }
112
+ @signal_handler_pipe_writer.write_nonblock('.')
113
+ @signal_handler_queue << signal
114
+ }
84
115
  end
85
116
 
86
117
  def state
@@ -112,12 +143,7 @@ module Smith
112
143
  end
113
144
  end
114
145
 
115
- protected
116
-
117
- def run_signal_handlers(sig, handlers)
118
- logger.debug { "Running signal handlers for agent: #{name}: #{sig}" }
119
- handlers.each { |handler| handler.call(sig) }
120
- end
146
+ private
121
147
 
122
148
  def setup_control_queue
123
149
  logger.debug { "Setting up control queue: #{control_queue_def.denormalise}" }
@@ -8,6 +8,7 @@ $:.unshift(Pathname.new(__FILE__).dirname.parent.expand_path)
8
8
 
9
9
  require 'smith'
10
10
  require 'smith/agent'
11
+ # require 'smith/synchronous_agent'
11
12
 
12
13
  module Smith
13
14
  class AgentBootstrap
@@ -92,7 +93,7 @@ module Smith
92
93
  private
93
94
 
94
95
  def write_pid_file
95
- @pid = Daemons::PidFile.new(Daemons::Pid.dir(:normal, Dir::tmpdir, nil), ".rubymas-#{@agent_uuid.snake_case}", true)
96
+ @pid = Daemons::PidFile.new(Daemons::Pid.dir(:normal, Dir::tmpdir, nil), ".smith-#{@agent_uuid}", true)
96
97
  @pid.pid = Process.pid
97
98
  end
98
99
 
@@ -1,12 +1,10 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require 'multi_json'
3
2
  require 'smith/messaging/queue'
4
3
 
5
4
  module Smith
6
5
  module Commands
7
6
  class Dump < CommandBase
8
7
  def execute
9
- MultiJson.use(:oj)
10
8
  dump
11
9
  end
12
10
 
@@ -1,6 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require 'yajl'
3
-
4
2
  require 'smith/messaging/queue'
5
3
 
6
4
  module Smith
@@ -1,7 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
-
3
- require 'multi_json'
4
-
5
2
  module Smith
6
3
  module Commands
7
4
  class Push < CommandBase
@@ -1,7 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
-
3
- require 'multi_json'
4
-
5
2
  module Smith
6
3
  module ACL
7
4
 
data/lib/smith/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Smith
2
- VERSION = "0.6.5"
2
+ VERSION = "0.6.5.1"
3
3
  end
data/lib/smith.rb CHANGED
@@ -6,6 +6,7 @@ require 'logging'
6
6
  require 'pathname'
7
7
  require 'protobuf'
8
8
  require 'fileutils'
9
+ require 'multi_json'
9
10
  require 'securerandom'
10
11
  require 'extlib/string'
11
12
  require 'extlib/inflection'
@@ -15,6 +16,8 @@ require_relative 'smith/config'
15
16
  require_relative 'smith/logger'
16
17
  require_relative 'smith/acl_compiler'
17
18
 
19
+ MultiJson.use(:oj)
20
+
18
21
  module Smith
19
22
  include Logger
20
23
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smith
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Heycock
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-07 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.10'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: amqp
15
29
  requirement: !ruby/object:Gem::Requirement