smith 0.6.5 → 0.6.5.1
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.
- checksums.yaml +4 -4
- data/lib/smith/agent.rb +38 -12
- data/lib/smith/bootstrap.rb +2 -1
- data/lib/smith/commands/smithctl/dump.rb +0 -2
- data/lib/smith/commands/smithctl/pop.rb +0 -2
- data/lib/smith/commands/smithctl/push.rb +0 -3
- data/lib/smith/messaging/acl/default.rb +0 -3
- data/lib/smith/version.rb +1 -1
- data/lib/smith.rb +3 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15e19b548b13abaa3401c8f90ac764f02d55d0e3
|
4
|
+
data.tar.gz: dd521bbdd079d43906581c451eabc27b6734d0a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
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}" }
|
data/lib/smith/bootstrap.rb
CHANGED
@@ -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), ".
|
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
|
|
data/lib/smith/version.rb
CHANGED
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-
|
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
|