slnky 0.9.5 → 0.10.0
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/slnky/cli/command.rb +2 -1
- data/lib/slnky/cli/service.rb +0 -1
- data/lib/slnky/cli.rb +11 -7
- data/lib/slnky/client.rb +23 -0
- data/lib/slnky/command/response.rb +2 -1
- data/lib/slnky/config.rb +13 -11
- data/lib/slnky/log.rb +20 -10
- data/lib/slnky/service.rb +1 -2
- data/lib/slnky/system.rb +2 -1
- data/lib/slnky/template/service/lib/slnky/NAME/client.rb.erb +5 -4
- data/lib/slnky/template/service/lib/slnky/NAME/command.rb.erb +18 -3
- data/lib/slnky/template/service/lib/slnky/NAME/mock.rb.erb +7 -5
- data/lib/slnky/template/service/lib/slnky/NAME/service.rb.erb +2 -2
- data/lib/slnky/template/service/spec/slnky/NAME/command_spec.rb.erb +2 -0
- data/lib/slnky/template/service/spec/slnky/NAME/service_spec.rb.erb +2 -1
- data/lib/slnky/template/service/test/config.yaml.erb +1 -1
- data/lib/slnky/version.rb +1 -1
- data/lib/slnky.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9205994e57ed75ad10a0fd88f243ef7e0fd95ed
|
4
|
+
data.tar.gz: d6314951e4589c72fcbbba5955d20cb34bf144cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d531aecffb5b4c89d24a3c93765da9311cd3b361e519d6c4ef96006e3f0a1e41a0fdffeb75285a511a2ab41eabadb3fa62f3ce8fff0c90c05fb146bb94f52286
|
7
|
+
data.tar.gz: 0925cc60acbb0c0c15202f55a2e5df4df099674686f646335356493341a4dd72133a1fadf4c0b3467f3ffb0006ce690f482aaec2962826314ddb2f49e40d0f8c
|
data/lib/slnky/cli/command.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Slnky
|
2
2
|
module CLI
|
3
3
|
class Command < Base
|
4
|
+
# option %w{-s --server}, '[SERVER]', 'set server url', environment_variable: 'SLNKY_SERVER'
|
4
5
|
option %w{-n --dry-run}, :flag, "just output the event, don't send"
|
5
6
|
option %w{-t --timeout}, '[TIMEOUT]', "time to wait for response in seconds", default: 10 do |t|
|
6
7
|
Integer(t)
|
@@ -15,13 +16,13 @@ module Slnky
|
|
15
16
|
|
16
17
|
def execute
|
17
18
|
@name = service
|
19
|
+
Slnky::Config.configure(@name, environment: environment)
|
18
20
|
data = {
|
19
21
|
name: "slnky.#{service}.command",
|
20
22
|
command: service == 'help' ? nil : command,
|
21
23
|
args: args,
|
22
24
|
response: "command-#{$$}",
|
23
25
|
}
|
24
|
-
Slnky::Config.configure('cli')
|
25
26
|
msg = Slnky::Message.new(data)
|
26
27
|
puts JSON.pretty_generate(msg.to_h) if dry_run?
|
27
28
|
amqp(msg) unless dry_run?
|
data/lib/slnky/cli/service.rb
CHANGED
@@ -6,7 +6,6 @@ module Slnky
|
|
6
6
|
n.gsub(/^slnky-/, '')
|
7
7
|
end
|
8
8
|
# option %w{-f --force}, :flag, "force overwrite of files"
|
9
|
-
option %w{-e --environment}, '[ENV]', 'the environment to run under', default: 'development', environment_variable: 'SLNKY_ENV'
|
10
9
|
def execute
|
11
10
|
lib = File.expand_path("#{Dir.pwd}/lib", __FILE__)
|
12
11
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
data/lib/slnky/cli.rb
CHANGED
@@ -14,13 +14,15 @@ module Slnky
|
|
14
14
|
exit(0)
|
15
15
|
end
|
16
16
|
|
17
|
-
option %w{-c --config}, '[CONFIG]', 'set config directory location', default: '~/.slnky', environment_variable: 'SLNKY_CONFIG' do |c|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
option %w{-c --config}, '[CONFIG]', 'set config directory location', default: '~/.slnky/config.yaml', environment_variable: 'SLNKY_CONFIG' do |c|
|
18
|
+
ENV['SLNKY_CONFIG'] = c
|
19
|
+
end
|
20
|
+
option %w{-s --server}, '[URL]', 'set server url', environment_variable: 'SLNKY_URL' do |u|
|
21
|
+
ENV['SLNKY_URL'] = u
|
22
|
+
end
|
23
|
+
option %w{-e --environment}, '[ENV]', 'the environment to run under', default: 'development', environment_variable: 'SLNKY_ENV' do |e|
|
24
|
+
ENV['SLNKY_ENV'] = e
|
21
25
|
end
|
22
|
-
|
23
|
-
option %w{-s --server}, '[URL]', 'set server url', environment_variable: 'SLNKY_URL'
|
24
26
|
end
|
25
27
|
|
26
28
|
class Main < Base
|
@@ -32,7 +34,9 @@ module Slnky
|
|
32
34
|
FileUtils.mkdir_p(dir)
|
33
35
|
defaults = {
|
34
36
|
slnky: {
|
35
|
-
|
37
|
+
development: {
|
38
|
+
url: server
|
39
|
+
}
|
36
40
|
}
|
37
41
|
}.deep_stringify_keys
|
38
42
|
File.open("#{dir}/config.yaml", "w+") { |f| f.write(defaults.to_yaml) }
|
data/lib/slnky/client.rb
ADDED
data/lib/slnky/config.rb
CHANGED
@@ -16,16 +16,16 @@ module Slnky
|
|
16
16
|
class Config < Data
|
17
17
|
class << self
|
18
18
|
def configure(name, config={})
|
19
|
+
config.deep_stringify_keys!
|
19
20
|
@name = name
|
20
|
-
@config
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
21
|
+
@environment = ENV['SLNKY_ENV'] || config['environment'] || 'development'
|
22
|
+
config['service'] = name
|
23
|
+
config['environment'] = @environment
|
24
|
+
file = ENV['SLNKY_CONFIG']||"~/.slnky/config.yaml"
|
25
|
+
config.merge!(config_file(file))
|
26
|
+
server = ENV['SLNKY_URL']||config['url']
|
27
|
+
config.merge!(config_server(server))
|
28
|
+
@config = self.new(config)
|
29
29
|
end
|
30
30
|
|
31
31
|
# def load_file(file)
|
@@ -52,8 +52,10 @@ module Slnky
|
|
52
52
|
return {} unless File.exists?(path)
|
53
53
|
template = Tilt::ERBTemplate.new(path)
|
54
54
|
output = template.render(self, {})
|
55
|
-
|
56
|
-
|
55
|
+
cfg = YAML.load(output)
|
56
|
+
cfg = cfg['slnky'] || cfg
|
57
|
+
cfg = cfg[@environment] || cfg
|
58
|
+
cfg
|
57
59
|
rescue => e
|
58
60
|
puts "failed to load file #{file}: #{e.message}"
|
59
61
|
{}
|
data/lib/slnky/log.rb
CHANGED
@@ -22,7 +22,7 @@ module Slnky
|
|
22
22
|
@response = false
|
23
23
|
case @config.environment
|
24
24
|
when 'production'
|
25
|
-
@local =
|
25
|
+
@local = Slnky::Log::Local.new
|
26
26
|
@service = Slnky::Log::Service.new
|
27
27
|
when 'test'
|
28
28
|
@local = false
|
@@ -35,6 +35,10 @@ module Slnky
|
|
35
35
|
|
36
36
|
[:debug, :info, :warn, :error].each do |l|
|
37
37
|
define_method(l) do |message|
|
38
|
+
# bl = @local ? 'x' : 'o'
|
39
|
+
# br = @remote ? 'x' : 'o'
|
40
|
+
# bs = @response ? 'x' : 'o'
|
41
|
+
# puts "#{l}:#{bl}#{br}#{bs} #{message}"
|
38
42
|
log(l, message)
|
39
43
|
end
|
40
44
|
end
|
@@ -69,6 +73,9 @@ module Slnky
|
|
69
73
|
def initialize
|
70
74
|
super
|
71
75
|
@logger = Logger.new(STDOUT)
|
76
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
77
|
+
"%-5s %s: %s: %s\n" % [severity, datetime, Slnky::System.pid, msg]
|
78
|
+
end
|
72
79
|
end
|
73
80
|
|
74
81
|
protected
|
@@ -85,28 +92,31 @@ module Slnky
|
|
85
92
|
|
86
93
|
def initialize
|
87
94
|
super
|
88
|
-
@service = Slnky::System.pid
|
95
|
+
@service = Slnky::System.pid
|
89
96
|
@hostname = Slnky::System.hostname
|
90
97
|
@ipaddress = Slnky::System.ipaddress
|
91
|
-
@transport = Slnky::Transport.instance
|
92
|
-
@exchange = nil
|
93
|
-
if @transport
|
94
|
-
@exchange = @transport.exchanges['logs']
|
95
|
-
end
|
96
98
|
end
|
97
99
|
|
98
100
|
protected
|
99
101
|
|
100
102
|
def log(level, message)
|
101
|
-
return unless
|
103
|
+
return unless exchange
|
102
104
|
data = {
|
103
|
-
service:
|
105
|
+
service: @service,
|
104
106
|
level: level,
|
105
107
|
hostname: @hostname,
|
106
108
|
ipaddress: @ipaddress,
|
107
109
|
message: message
|
108
110
|
}
|
109
|
-
|
111
|
+
exchange.publish(msg(data))
|
112
|
+
end
|
113
|
+
|
114
|
+
def transport
|
115
|
+
@transport ||= Slnky::Transport.instance
|
116
|
+
end
|
117
|
+
|
118
|
+
def exchange
|
119
|
+
@exchange ||= transport.exchanges['logs']
|
110
120
|
end
|
111
121
|
|
112
122
|
def msg(data)
|
data/lib/slnky/service.rb
CHANGED
@@ -13,13 +13,12 @@ module Slnky
|
|
13
13
|
|
14
14
|
def initialize
|
15
15
|
config.service = name
|
16
|
-
@environment = config.environment
|
17
16
|
@server_down = false
|
18
17
|
end
|
19
18
|
|
20
19
|
def start
|
21
20
|
transport.start!(self) do |_|
|
22
|
-
log.info "running"
|
21
|
+
log.info "#{config.service} running #{config.environment}"
|
23
22
|
run
|
24
23
|
|
25
24
|
subscriber.add "slnky.#{name}.command", :handle_command
|
data/lib/slnky/system.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module Slnky
|
2
2
|
module <%= cap %>
|
3
|
-
class Client
|
4
|
-
def initialize
|
5
|
-
|
3
|
+
class Client < Slnky::Client::Base
|
4
|
+
def initialize
|
5
|
+
# you can load any configurations from the server here
|
6
|
+
# @param = config.<%= name %>.param
|
6
7
|
end
|
7
8
|
|
8
|
-
|
9
|
+
# implement communications with supporting services
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -6,9 +6,24 @@ module Slnky
|
|
6
6
|
@client ||= Slnky::<%= cap %>::Client.new(config)
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
# use docopt to define arguments and options
|
10
|
+
command :echo, 'respond with the given arguments', <<-USAGE.strip_heredoc
|
11
|
+
Usage: echo [options] ARGS...
|
12
|
+
|
13
|
+
-h --help print help.
|
14
|
+
-x --times=TIMES print x times [default: 1].
|
15
|
+
USAGE
|
16
|
+
|
17
|
+
# handler methods receive request, response, and options objects
|
18
|
+
def handle_echo(request, response, opts)
|
19
|
+
# parameters (non-option arguments) are available as accessors
|
20
|
+
args = opts.args
|
21
|
+
# as are the options themselves (by their 'long' name)
|
22
|
+
1.upto(opts.times.to_i) do |i|
|
23
|
+
# just use the log object to respond, it will automatically send it
|
24
|
+
# to the correct channel.
|
25
|
+
log.info args.join(" ")
|
26
|
+
end
|
12
27
|
end
|
13
28
|
end
|
14
29
|
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
module Slnky
|
2
2
|
module <%= cap %>
|
3
|
-
class Mock
|
4
|
-
|
3
|
+
class Mock < Slnky::<%= cap %>::Client
|
4
|
+
# unless there's something special you need to do in the initializer
|
5
|
+
# use the one provided by the actual client object
|
6
|
+
# def initialize
|
7
|
+
#
|
8
|
+
# end
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
10
|
+
# override methods of the client here to mock them for testing
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -6,12 +6,12 @@ module Slnky
|
|
6
6
|
@client ||= Slnky::<%= cap %>::Client.new(config)
|
7
7
|
end
|
8
8
|
|
9
|
-
subscribe 'slnky.service.test', :
|
9
|
+
subscribe 'slnky.service.test', :handle_test
|
10
10
|
# you can also subscribe to heirarchies, this gets
|
11
11
|
# all events under something.happened
|
12
12
|
# subscribe 'something.happened.*', :other_handler
|
13
13
|
|
14
|
-
def
|
14
|
+
def handle_test(name, data)
|
15
15
|
name == 'slnky.service.test' && data.hello == 'world!'
|
16
16
|
end
|
17
17
|
end
|
@@ -12,7 +12,9 @@ describe Slnky::<%= cap %>::Command do
|
|
12
12
|
let(:help_response) { slnky_response('test-route', 'spec') }
|
13
13
|
|
14
14
|
it 'handles echo' do
|
15
|
+
# make sure the command handler does not raise an error
|
15
16
|
expect { subject.handle(echo.name, echo.payload, echo_response) }.to_not raise_error
|
17
|
+
# validate that the correct output is available in the response object
|
16
18
|
expect(echo_response.log).to include("test echo")
|
17
19
|
end
|
18
20
|
|
@@ -9,6 +9,7 @@ describe Slnky::<%= cap %>::Service do
|
|
9
9
|
let(:test_event) { event_load('test')}
|
10
10
|
|
11
11
|
it 'handles event' do
|
12
|
-
|
12
|
+
# test that the handler method receives and responds correctly
|
13
|
+
expect(subject.handle_test(test_event.name, test_event.payload)).to eq(true)
|
13
14
|
end
|
14
15
|
end
|
@@ -3,5 +3,5 @@
|
|
3
3
|
# this file is processed through ERB, you can inject
|
4
4
|
# values into the config from the environment, by specifying them
|
5
5
|
# in the .env file
|
6
|
-
environment:
|
6
|
+
environment: test # should specify this
|
7
7
|
service: <%= name %> # just an example
|
data/lib/slnky/version.rb
CHANGED
data/lib/slnky.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slnky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shawn Catanzarite
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -207,6 +207,7 @@ files:
|
|
207
207
|
- lib/slnky/cli/generate.rb
|
208
208
|
- lib/slnky/cli/notify.rb
|
209
209
|
- lib/slnky/cli/service.rb
|
210
|
+
- lib/slnky/client.rb
|
210
211
|
- lib/slnky/command.rb
|
211
212
|
- lib/slnky/command/request.rb
|
212
213
|
- lib/slnky/command/response.rb
|