slnky 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/capistrano/slnky/templates/upstart.conf.erb +1 -1
- data/lib/slnky/command.rb +2 -4
- data/lib/slnky/command/response.rb +24 -5
- data/lib/slnky/config.rb +17 -3
- data/lib/slnky/spec/helper.rb +36 -0
- data/lib/slnky/template/service/Gemfile.erb +1 -0
- data/lib/slnky/template/service/Rakefile.erb +20 -0
- data/lib/slnky/template/service/spec/slnky/NAME/command_spec.rb.erb +13 -7
- data/lib/slnky/template/service/spec/slnky/NAME/service_spec.rb.erb +2 -2
- data/lib/slnky/template/service/spec/spec_helper.rb.erb +2 -37
- data/lib/slnky/template/service/test/commands/help.json +9 -0
- data/lib/slnky/transport.rb +10 -0
- data/lib/slnky/version.rb +1 -1
- metadata +4 -3
- data/lib/slnky/template/service/Rakefile +0 -3
- data/lib/slnky/template/service/service-slnky-NAME.erb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37ab3b0c1f8e28e91be149e5500fca4ce689b91b
|
4
|
+
data.tar.gz: 8f5dc8b34b0042c7ee44f636b3441da878ef3198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11787283f2e825eebb57cfd22b387447101a5f8f9bff2de344ed325a14c77c10202d28c616e10da0c430f1da77b4288ce4ed4475df9aec427ecec4ee4d41034e
|
7
|
+
data.tar.gz: a786cfd4158b024e21b7f70a58566d72be0d6c2d3768146c9f8323dc055d92305eddc741956522f58762b81f5b19e0bb4f3355f88fcb9ad349c7968352d01752
|
@@ -14,4 +14,4 @@ export SLNKY_SCRIPT
|
|
14
14
|
exec start-stop-daemon --start \
|
15
15
|
--chdir ${SLNKY_DIR} \
|
16
16
|
--make-pidfile --pidfile ${SLNKY_DIR}/tmp/pids/${SLNKY_SERVICE}.pid \
|
17
|
-
--exec /usr/local/rvm/bin/rvm -- ${SLNKY_RVM} do bundle exec
|
17
|
+
--exec /usr/local/rvm/bin/rvm -- ${SLNKY_RVM} do bundle exec slnky service run -e production $SLNKY_SERVICE
|
data/lib/slnky/command.rb
CHANGED
@@ -10,10 +10,10 @@ module Slnky
|
|
10
10
|
@commands = self.class.commands
|
11
11
|
end
|
12
12
|
|
13
|
-
def handle(event, data)
|
13
|
+
def handle(event, data, response=nil)
|
14
14
|
begin
|
15
15
|
req = Slnky::Command::Request.new(data)
|
16
|
-
res = Slnky::Command::Response.new(data.response, name)
|
16
|
+
res = response || Slnky::Command::Response.new(data.response, name)
|
17
17
|
log.response = res
|
18
18
|
res.start!
|
19
19
|
|
@@ -48,8 +48,6 @@ module Slnky
|
|
48
48
|
end
|
49
49
|
rescue Docopt::Exit => e
|
50
50
|
log.info e.message
|
51
|
-
rescue => e
|
52
|
-
log.error "error in #{req.command}: #{e.message} at #{e.backtrace.first}"
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
@@ -1,17 +1,18 @@
|
|
1
1
|
module Slnky
|
2
2
|
module Command
|
3
3
|
class Response
|
4
|
+
attr_reader :log
|
5
|
+
|
4
6
|
def initialize(route, service)
|
5
|
-
@transport = Slnky::Transport.instance
|
6
|
-
@channel = @transport.channel
|
7
|
-
@exchange = @transport.exchanges['response']
|
8
7
|
@route = route
|
9
8
|
@service = Slnky::System.pid(service)
|
10
|
-
|
9
|
+
@started = false
|
10
|
+
@log = []
|
11
11
|
end
|
12
12
|
|
13
13
|
[:info, :warn, :error].each do |l|
|
14
14
|
define_method(l) do |message|
|
15
|
+
start! unless @started
|
15
16
|
pub l, message
|
16
17
|
end
|
17
18
|
end
|
@@ -22,12 +23,17 @@ module Slnky
|
|
22
23
|
|
23
24
|
def start!
|
24
25
|
pub :start, "start"
|
26
|
+
@started = true
|
25
27
|
end
|
26
28
|
|
27
29
|
def done!
|
28
30
|
pub :complete, "complete"
|
29
31
|
end
|
30
32
|
|
33
|
+
def exchange=(exchange)
|
34
|
+
@exchange = exchange
|
35
|
+
end
|
36
|
+
|
31
37
|
private
|
32
38
|
|
33
39
|
def msg(level, message)
|
@@ -36,7 +42,20 @@ module Slnky
|
|
36
42
|
|
37
43
|
def pub(level, message)
|
38
44
|
# puts "#{level} #{message}"
|
39
|
-
|
45
|
+
exchange.publish(msg(level, message), routing_key: @route)
|
46
|
+
@log << message
|
47
|
+
end
|
48
|
+
|
49
|
+
def exchange
|
50
|
+
@exchange ||= transport.exchanges['response']
|
51
|
+
end
|
52
|
+
|
53
|
+
def transport
|
54
|
+
@transport ||= Slnky::Transport.instance
|
55
|
+
end
|
56
|
+
|
57
|
+
def channel
|
58
|
+
@channel ||= transport.channel
|
40
59
|
end
|
41
60
|
end
|
42
61
|
end
|
data/lib/slnky/config.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
require 'erb'
|
5
|
+
require 'tilt'
|
6
|
+
require 'dotenv'
|
7
|
+
Dotenv.load
|
2
8
|
|
3
9
|
module Slnky
|
4
10
|
class << self
|
@@ -14,7 +20,7 @@ module Slnky
|
|
14
20
|
@config ||= begin
|
15
21
|
config['service'] = name
|
16
22
|
config['environment'] ||= 'development'
|
17
|
-
file = ENV['
|
23
|
+
file = ENV['SLNKY_CONFIG']||"~/.slnky/config.yaml"
|
18
24
|
config.merge!(config_file(file))
|
19
25
|
server = ENV['SLNKY_SERVER'] || config['url']
|
20
26
|
config.merge!(config_server(server))
|
@@ -43,14 +49,22 @@ module Slnky
|
|
43
49
|
def config_file(file)
|
44
50
|
path = File.expand_path(file)
|
45
51
|
return {} unless File.exists?(path)
|
46
|
-
|
52
|
+
template = Tilt::ERBTemplate.new(path)
|
53
|
+
output = template.render(self, {})
|
54
|
+
d = YAML.load(output)
|
47
55
|
d['slnky'] ? d['slnky'] : d
|
56
|
+
rescue => e
|
57
|
+
puts "failed to load file #{file}: #{e.message}"
|
58
|
+
{}
|
48
59
|
end
|
49
60
|
|
50
61
|
def config_server(server)
|
51
62
|
return {} unless server
|
52
63
|
server = "https://#{server}" unless server =~ /^http/
|
53
|
-
JSON.parse(open("#{server}/configs/#{@name}") { |f| f.read })
|
64
|
+
JSON.parse(open("#{server}/configs/#{@name}") { |f| f.read })
|
65
|
+
rescue => e
|
66
|
+
puts "failed to load server #{server}: #{e.message}"
|
67
|
+
{}
|
54
68
|
end
|
55
69
|
end
|
56
70
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'yaml'
|
3
|
+
require 'erb'
|
4
|
+
require 'tilt'
|
5
|
+
require 'dotenv'
|
6
|
+
require 'slnky'
|
7
|
+
|
8
|
+
def slnky_event(name)
|
9
|
+
@events ||= {}
|
10
|
+
@events[name] ||= begin
|
11
|
+
file = File.expand_path("#{Dir.pwd}/test/events/#{name}.json", __FILE__)
|
12
|
+
raise "file #{file} not found" unless File.exists?(file)
|
13
|
+
Slnky::Message.new(JSON.parse(File.read(file)))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def slnky_command(name)
|
18
|
+
@commands ||= {}
|
19
|
+
@commands[name] ||= begin
|
20
|
+
file = File.expand_path("#{Dir.pwd}/test/commands/#{name}.json", __FILE__)
|
21
|
+
raise "file #{file} not found" unless File.exists?(file)
|
22
|
+
Slnky::Command::Request.new(JSON.parse(File.read(file)))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def slnky_response(route, service)
|
27
|
+
@responses ||= {}
|
28
|
+
@responses[route] ||= begin
|
29
|
+
response = Slnky::Command::Response.new(route, service)
|
30
|
+
response.exchange = Slnky::Transport::MockExchange.new
|
31
|
+
response
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
ENV['SLNKY_CONFIG'] = File.expand_path("#{Dir.pwd}/test/config.yaml", __FILE__)
|
36
|
+
Slnky::Config.configure('spec')
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
RSpec::Core::RakeTask.new(:spec)
|
3
|
+
task :default => :spec
|
4
|
+
|
5
|
+
namespace :travis do
|
6
|
+
desc 'load .env variables into travis env'
|
7
|
+
task :env do
|
8
|
+
# use this to push variables to travis
|
9
|
+
# the names are the lower case names of the env
|
10
|
+
# variables set in your .env file
|
11
|
+
# %w{env_var_name}.each do |w|
|
12
|
+
# key = w.upcase
|
13
|
+
# `travis env set -- #{key} '#{ENV[key]}'`
|
14
|
+
# end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
task :run do
|
19
|
+
sh "slnky service run <%= name %>"
|
20
|
+
end
|
@@ -2,16 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Slnky::<%= cap %>::Command do
|
4
4
|
subject do
|
5
|
-
s = described_class.new
|
6
|
-
s.client = Slnky::<%= cap %>::Mock.new
|
5
|
+
s = described_class.new
|
6
|
+
s.client = Slnky::<%= cap %>::Mock.new
|
7
7
|
s
|
8
8
|
end
|
9
|
-
let(:echo) {
|
10
|
-
let(:
|
9
|
+
let(:echo) { slnky_command('echo') }
|
10
|
+
let(:help) { slnky_command('help') }
|
11
|
+
let(:echo_response) { slnky_response('test-route', 'spec') }
|
12
|
+
let(:help_response) { slnky_response('test-route', 'spec') }
|
11
13
|
|
12
14
|
it 'handles echo' do
|
13
|
-
|
14
|
-
expect(
|
15
|
-
|
15
|
+
expect { subject.handle(echo.name, echo.payload, echo_response) }.to_not raise_error
|
16
|
+
expect(echo_response.log).to include("test echo")
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'handles help' do
|
20
|
+
expect { subject.handle(help.name, help.payload, help_response) }.to_not raise_error
|
21
|
+
expect(help_response.log).to include("<%= name %> help: print help")
|
16
22
|
end
|
17
23
|
end
|
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Slnky::<%= cap %>::Service do
|
4
4
|
subject do
|
5
|
-
s = described_class.new
|
6
|
-
s.client = Slnky::<%= cap %>::Mock.new
|
5
|
+
s = described_class.new
|
6
|
+
s.client = Slnky::<%= cap %>::Mock.new
|
7
7
|
s
|
8
8
|
end
|
9
9
|
let(:test_event) { event_load('test')}
|
@@ -1,38 +1,3 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
-
require 'slnky'
|
3
|
-
require 'slnky
|
4
|
-
require 'yaml'
|
5
|
-
require 'erb'
|
6
|
-
require 'tilt'
|
7
|
-
|
8
|
-
require 'dotenv'
|
9
|
-
@dotenv = Dotenv.load
|
10
|
-
|
11
|
-
def event(name)
|
12
|
-
@events ||= {}
|
13
|
-
@events[name] ||= begin
|
14
|
-
file = File.expand_path("../../test/events/#{name}.json", __FILE__)
|
15
|
-
raise "file #{file} not found" unless File.exists?(file)
|
16
|
-
Slnky::Data.new(JSON.parse(File.read(file)))
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def command(name)
|
21
|
-
@commands ||= {}
|
22
|
-
@commands[name] ||= begin
|
23
|
-
file = File.expand_path("../../test/commands/#{name}.json", __FILE__)
|
24
|
-
raise "file #{file} not found" unless File.exists?(file)
|
25
|
-
Slnky::Command::Request.new(JSON.parse(File.read(file)))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_config
|
30
|
-
@config ||= begin
|
31
|
-
file = File.expand_path("../../test/config.yaml", __FILE__)
|
32
|
-
template = Tilt::ERBTemplate.new(file)
|
33
|
-
output = template.render(self, @dotenv)
|
34
|
-
cfg = Slnky::Data.new(YAML.load(output))
|
35
|
-
cfg.environment = 'test'
|
36
|
-
cfg
|
37
|
-
end
|
38
|
-
end
|
2
|
+
require 'slnky/spec/helper'
|
3
|
+
require 'slnky/chef'
|
data/lib/slnky/transport.rb
CHANGED
@@ -94,5 +94,15 @@ module Slnky
|
|
94
94
|
@queues[desc] ||= @channel.queue(name, options).bind(@exchanges[exchange], bindoptions)
|
95
95
|
end
|
96
96
|
end
|
97
|
+
|
98
|
+
class MockExchange
|
99
|
+
def initialize
|
100
|
+
@verbose = false
|
101
|
+
end
|
102
|
+
|
103
|
+
def publish(object, options={})
|
104
|
+
puts "publish: #{object.inspect}: #{options.inspect}" if @verbose
|
105
|
+
end
|
106
|
+
end
|
97
107
|
end
|
98
108
|
end
|
data/lib/slnky/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slnky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shawn Catanzarite
|
@@ -221,6 +221,7 @@ files:
|
|
221
221
|
- lib/slnky/service.rb
|
222
222
|
- lib/slnky/service/subscriber.rb
|
223
223
|
- lib/slnky/service/timer.rb
|
224
|
+
- lib/slnky/spec/helper.rb
|
224
225
|
- lib/slnky/system.rb
|
225
226
|
- lib/slnky/template/service/.env.sample
|
226
227
|
- lib/slnky/template/service/.gitignore.erb
|
@@ -230,7 +231,7 @@ files:
|
|
230
231
|
- lib/slnky/template/service/CODE_OF_CONDUCT.md
|
231
232
|
- lib/slnky/template/service/Capfile
|
232
233
|
- lib/slnky/template/service/Gemfile.erb
|
233
|
-
- lib/slnky/template/service/Rakefile
|
234
|
+
- lib/slnky/template/service/Rakefile.erb
|
234
235
|
- lib/slnky/template/service/config/deploy.rb.erb
|
235
236
|
- lib/slnky/template/service/config/deploy/production.rb
|
236
237
|
- lib/slnky/template/service/config/deploy/staging.rb
|
@@ -242,11 +243,11 @@ files:
|
|
242
243
|
- lib/slnky/template/service/lib/slnky/NAME/mock.rb.erb
|
243
244
|
- lib/slnky/template/service/lib/slnky/NAME/service.rb.erb
|
244
245
|
- lib/slnky/template/service/log/.keep
|
245
|
-
- lib/slnky/template/service/service-slnky-NAME.erb
|
246
246
|
- lib/slnky/template/service/spec/slnky/NAME/command_spec.rb.erb
|
247
247
|
- lib/slnky/template/service/spec/slnky/NAME/service_spec.rb.erb
|
248
248
|
- lib/slnky/template/service/spec/spec_helper.rb.erb
|
249
249
|
- lib/slnky/template/service/test/commands/echo.json.erb
|
250
|
+
- lib/slnky/template/service/test/commands/help.json
|
250
251
|
- lib/slnky/template/service/test/config.yaml.erb
|
251
252
|
- lib/slnky/template/service/test/events/test.json
|
252
253
|
- lib/slnky/transport.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
lib = File.expand_path('../lib', __FILE__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
|
6
|
-
require 'rubygems'
|
7
|
-
require 'bundler/setup'
|
8
|
-
require 'dotenv'
|
9
|
-
require 'daemons'
|
10
|
-
require 'slnky/<%= name %>'
|
11
|
-
Dotenv.load
|
12
|
-
|
13
|
-
env = ARGV[0]
|
14
|
-
|
15
|
-
# Become a daemon
|
16
|
-
# Daemons.daemonize if env == 'production'
|
17
|
-
|
18
|
-
Slnky::<%= cap %>::Service.new(ENV['SLNKY_URL'], environment: env).start
|