larva 0.9.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/bin/larva +2 -66
- data/lib/larva.rb +10 -8
- data/lib/larva/configurator.rb +2 -11
- data/lib/larva/daemon.rb +0 -1
- data/lib/larva/daemon_creator.rb +68 -0
- data/lib/larva/message_replayer.rb +1 -1
- data/lib/larva/mocker.rb +2 -9
- data/lib/larva/version.rb +1 -1
- data/template/Gemfile +0 -2
- data/template/README.md +0 -3
- data/template/lib/larva_spawn.rb +0 -1
- data/template/lib/larva_spawn/daemon.rb +2 -2
- data/template/lib/larva_spawn/processors/user_processor.rb +12 -0
- data/template/lib/tasks/larva_spawn.rake +0 -1
- data/template/test/processors/user_processor_test.rb +11 -0
- data/template/test/test_helper.rb +0 -2
- data/test/configurator_test.rb +0 -43
- data/test/mocker_test.rb +0 -8
- data/test/test_helper.rb +0 -23
- metadata +7 -6
- data/template/config/meducation-sdk.yml.optional +0 -6
- data/template/lib/larva_spawn/processors/media_file_processor.rb +0 -15
- data/template/test/processors/media_file_processor_test.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56edc62f830f8beaa3862dcb8ff381f1cd4b35d2
|
4
|
+
data.tar.gz: 7a77450848d9d87cb6b50f9ac95486cce0fdd8c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 330518dec7552c9150b65fa6ae78c7f12283da832344be782f4db5a48c3795aee8463cdb2f3809f78dc3d260269467fb43604fe06b204d64421c5009697ec923
|
7
|
+
data.tar.gz: b928a17b94ce057fd544c39824dfe9be8fcdabbdd72c97b070210ce30339de611cb0d271fe64f2544eff418c9e915109b45ee8a9e2d291b12ac5d08a0827fb71
|
data/CHANGELOG.md
CHANGED
data/bin/larva
CHANGED
@@ -1,70 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'active_support/core_ext'
|
5
|
-
|
6
|
-
class DaemonCreator
|
7
|
-
def self.create(*args)
|
8
|
-
new(*args).create
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize(pwd, daemon_name)
|
12
|
-
@pwd = pwd
|
13
|
-
@template_dir = File.expand_path('../../template', __FILE__)
|
14
|
-
@daemon_name = daemon_name
|
15
|
-
@daemon_dir = "#{pwd}/#{daemon_name}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def create
|
19
|
-
error_exit("Please provide a daemon name. e.g. larva spawn my_daemon_name") if @daemon_name.blank?
|
20
|
-
error_exit("Directory #{@daemon_dir} already exists. Please remove it before continuing.") if File.exists?(@daemon_dir)
|
21
|
-
|
22
|
-
# Copy template directory
|
23
|
-
FileUtils.cp_r(@template_dir, @daemon_dir)
|
24
|
-
rename_directories
|
25
|
-
rename_files
|
26
|
-
rename_file_contents
|
27
|
-
git_it_up
|
28
|
-
$stdout.puts "Daemon '#{@daemon_name}' created succesfully :)"
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def rename_directories
|
34
|
-
Dir.glob("#{@daemon_dir}/**/*/").each do |original_path|
|
35
|
-
new_path = original_path.gsub('larva_spawn', @daemon_name)
|
36
|
-
next if new_path == original_path
|
37
|
-
|
38
|
-
FileUtils.mv(original_path, new_path)
|
39
|
-
rename_directories
|
40
|
-
return
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def rename_files
|
45
|
-
Dir.glob("#{@daemon_dir}/**/*").each do |original_path|
|
46
|
-
new_path = original_path.gsub('larva_spawn', @daemon_name)
|
47
|
-
FileUtils.mv(original_path, new_path) if new_path != original_path
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def rename_file_contents
|
52
|
-
Dir.glob("#{@daemon_dir}/**/*").each do |path|
|
53
|
-
next unless File.file?(path)
|
54
|
-
contents = File.read(path)
|
55
|
-
File.open(path, 'w+') do |file|
|
56
|
-
contents.gsub!("LarvaSpawn", @daemon_name.camelize)
|
57
|
-
contents.gsub!("larva_spawn", @daemon_name)
|
58
|
-
contents.gsub!("LARVA_SPAWN", @daemon_name.upcase)
|
59
|
-
file.write(contents)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def git_it_up
|
65
|
-
`cd #{@daemon_name} && git init && git add . && git commit -am "Create basic daemon" && cd ..`
|
66
|
-
end
|
67
|
-
end
|
3
|
+
require 'larva'
|
68
4
|
|
69
5
|
def error_exit(error)
|
70
6
|
$stderr.puts "!! Error: #{error}"
|
@@ -72,4 +8,4 @@ def error_exit(error)
|
|
72
8
|
end
|
73
9
|
|
74
10
|
error_exit("Please provide a valid command. Valid commands: spawn") unless ARGV[0] == "spawn"
|
75
|
-
DaemonCreator.create(ENV["PWD"], ARGV[1])
|
11
|
+
Larva::DaemonCreator.create(ENV["PWD"], ARGV[1])
|
data/lib/larva.rb
CHANGED
@@ -2,14 +2,16 @@ require 'active_support/core_ext'
|
|
2
2
|
require 'filum'
|
3
3
|
require 'propono'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
require_relative 'larva/configuration'
|
6
|
+
require_relative 'larva/configurator'
|
7
|
+
require_relative 'larva/mocker'
|
8
|
+
require_relative 'larva/listener'
|
9
|
+
require_relative 'larva/processor'
|
10
|
+
require_relative 'larva/worker_pool'
|
11
|
+
require_relative 'larva/daemon'
|
12
|
+
require_relative 'larva/message_replayer'
|
13
|
+
|
14
|
+
require_relative 'larva/daemon_creator'
|
13
15
|
|
14
16
|
module Larva
|
15
17
|
class LarvaError < StandardError
|
data/lib/larva/configurator.rb
CHANGED
@@ -18,17 +18,6 @@ module Larva
|
|
18
18
|
Filum.setup(@logfile)
|
19
19
|
Filum.logger.info "Configuring Daemon"
|
20
20
|
|
21
|
-
if meducation_sdk_config = parse_config_file('meducation-sdk.yml')
|
22
|
-
MeducationSDK.config do |config|
|
23
|
-
config.access_id = meducation_sdk_config[:access_id]
|
24
|
-
|
25
|
-
# Don't use fetch for these as nil values might be deliberately passed it
|
26
|
-
config.secret_key = @options[:meducation_sdk_secret_key] || meducation_sdk_config[:secret_key]
|
27
|
-
config.endpoint = @options[:meducation_sdk_endpoint ] || "http://localhost:3000/spi" if @env == 'development'
|
28
|
-
config.logger = Filum.logger
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
21
|
if propono_config = parse_config_file('propono.yml')
|
33
22
|
Propono.config do |config|
|
34
23
|
config.use_iam_profile = propono_config[:use_iam_profile]
|
@@ -42,6 +31,8 @@ module Larva
|
|
42
31
|
config.logger = Filum.logger
|
43
32
|
end
|
44
33
|
end
|
34
|
+
|
35
|
+
after_configure if respond_to?(:after_configure)
|
45
36
|
end
|
46
37
|
|
47
38
|
private
|
data/lib/larva/daemon.rb
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
4
|
+
module Larva
|
5
|
+
class DaemonCreator
|
6
|
+
def self.create(*args)
|
7
|
+
new(*args).create
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :template_dir, :daemon_name, :daemon_dir
|
11
|
+
def initialize(pwd, daemon_name)
|
12
|
+
@template_dir = File.expand_path('../../../template', __FILE__)
|
13
|
+
@daemon_name = daemon_name
|
14
|
+
@daemon_dir = "#{pwd}/#{daemon_name}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def create
|
18
|
+
error_exit("Please provide a daemon name. e.g. larva spawn my_daemon_name") if daemon_name.blank?
|
19
|
+
error_exit("Directory #{daemon_dir} already exists. Please remove it before continuing.") if File.exists?(daemon_dir)
|
20
|
+
|
21
|
+
# Copy template directory
|
22
|
+
FileUtils.cp_r(template_dir, daemon_dir)
|
23
|
+
rename_directories
|
24
|
+
rename_files
|
25
|
+
rename_file_contents
|
26
|
+
alter_files if respond_to?(:alter_files)
|
27
|
+
git_it_up
|
28
|
+
$stdout.puts "Daemon '#{daemon_name}' created succesfully :)"
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def rename_directories
|
34
|
+
Dir.glob("#{daemon_dir}/**/*/").each do |original_path|
|
35
|
+
new_path = original_path.gsub('larva_spawn', daemon_name)
|
36
|
+
next if new_path == original_path
|
37
|
+
|
38
|
+
FileUtils.mv(original_path, new_path)
|
39
|
+
rename_directories
|
40
|
+
return
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def rename_files
|
45
|
+
Dir.glob("#{daemon_dir}/**/*").each do |original_path|
|
46
|
+
new_path = original_path.gsub('larva_spawn', daemon_name)
|
47
|
+
FileUtils.mv(original_path, new_path) if new_path != original_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def rename_file_contents
|
52
|
+
Dir.glob("#{daemon_dir}/**/*").each do |path|
|
53
|
+
next unless File.file?(path)
|
54
|
+
contents = File.read(path)
|
55
|
+
File.open(path, 'w+') do |file|
|
56
|
+
contents.gsub!("LarvaSpawn", daemon_name.camelize)
|
57
|
+
contents.gsub!("larva_spawn", daemon_name)
|
58
|
+
contents.gsub!("LARVA_SPAWN", daemon_name.upcase)
|
59
|
+
file.write(contents)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def git_it_up
|
65
|
+
`cd #{daemon_name} && git init && git add . && git commit -am "Create basic daemon" && cd ..`
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -24,7 +24,7 @@ module Larva
|
|
24
24
|
else
|
25
25
|
messages.each do |msg|
|
26
26
|
sqs_message = Propono::SqsMessage.new(msg)
|
27
|
-
|
27
|
+
Filum.logger.info "Message : #{sqs_message}"
|
28
28
|
sqs.send_message(original_url, sqs_message.to_json_with_exception(StandardError.new "Fake Exception"))
|
29
29
|
sqs.delete_message(failed_url, msg['ReceiptHandle'])
|
30
30
|
end
|
data/lib/larva/mocker.rb
CHANGED
@@ -4,18 +4,11 @@ module Larva
|
|
4
4
|
Filum.setup('./log/test.log')
|
5
5
|
Propono::Publisher.any_instance.stubs(:publish_via_sns)
|
6
6
|
|
7
|
-
if const_defined?("MeducationSDK")
|
8
|
-
MeducationSDK.config do |config|
|
9
|
-
config.endpoint = "http://localhost:3000/spi"
|
10
|
-
config.access_id = "Daemon"
|
11
|
-
config.secret_key = "foobar"
|
12
|
-
config.logger = Filum.logger
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
7
|
Propono.config do |config|
|
17
8
|
config.logger = Filum.logger
|
18
9
|
end
|
10
|
+
|
11
|
+
after_mock if respond_to?(:after_mock)
|
19
12
|
end
|
20
13
|
end
|
21
14
|
end
|
data/lib/larva/version.rb
CHANGED
data/template/Gemfile
CHANGED
data/template/README.md
CHANGED
@@ -4,9 +4,6 @@
|
|
4
4
|
|
5
5
|
There's a few things you need to do:
|
6
6
|
|
7
|
-
- If you're using the SDK:
|
8
|
-
- Uncomment the lines in the `Gemfile` and `test/test_helper.rb`
|
9
|
-
- Rename `config/meducation-sdk.yml.optional` to `config/meducation-sdk.yml`
|
10
7
|
- Run `bundle install`
|
11
8
|
- Run `bundle exec rake test`
|
12
9
|
- Add your keys to `config/*`
|
data/template/lib/larva_spawn.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'larva_spawn/processors/
|
1
|
+
require 'larva_spawn/processors/user_processor'
|
2
2
|
|
3
3
|
module LarvaSpawn
|
4
4
|
class Daemon < Larva::Daemon
|
5
5
|
def initialize(options = {})
|
6
6
|
processors = {
|
7
|
-
|
7
|
+
user: UserProcessor
|
8
8
|
}
|
9
9
|
super(processors, options)
|
10
10
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module LarvaSpawn
|
4
|
+
class UserProcessorTest < Minitest::Test
|
5
|
+
def test_everything_is_wired_up_correctly
|
6
|
+
message = { entity: "user", action: "created", foo: 'bar'}
|
7
|
+
LarvaSpawn::UserProcessor.any_instance.expects(:do_something).with('bar')
|
8
|
+
LarvaSpawn::UserProcessor.process(message)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/test/configurator_test.rb
CHANGED
@@ -27,49 +27,6 @@ module Larva
|
|
27
27
|
assert_equal logfile, Filum.logger.logfile
|
28
28
|
end
|
29
29
|
|
30
|
-
def test_sdk_secret_key_can_be_overriden
|
31
|
-
sdk_yaml_path = File.expand_path('../../template/config/meducation-sdk.yml', __FILE__)
|
32
|
-
begin
|
33
|
-
optional_sdk_yaml_path = "#{sdk_yaml_path}.optional"
|
34
|
-
`cp #{optional_sdk_yaml_path} #{sdk_yaml_path}`
|
35
|
-
secret_key = "Foobar!"
|
36
|
-
Configurator.configure(logfile: logfile, config_dir: config_dir, meducation_sdk_secret_key: secret_key)
|
37
|
-
assert_equal secret_key, MeducationSDK.config.secret_key
|
38
|
-
ensure
|
39
|
-
`rm #{sdk_yaml_path}`
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_meducation_sdk_gets_config_in_dev
|
44
|
-
sdk_yaml_path = File.expand_path('../../template/config/meducation-sdk.yml', __FILE__)
|
45
|
-
begin
|
46
|
-
optional_sdk_yaml_path = "#{sdk_yaml_path}.optional"
|
47
|
-
`cp #{optional_sdk_yaml_path} #{sdk_yaml_path}`
|
48
|
-
Configurator.configure(config_dir: config_dir, logfile: logfile)
|
49
|
-
assert_equal "LarvaSpawn", MeducationSDK.config.access_id
|
50
|
-
assert_equal "foobar", MeducationSDK.config.secret_key
|
51
|
-
assert_equal Filum.logger, MeducationSDK.config.logger
|
52
|
-
assert_equal "http://localhost:3000/spi", MeducationSDK.config.endpoint
|
53
|
-
ensure
|
54
|
-
`rm #{sdk_yaml_path}`
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_meducation_sdk_gets_config_in_production
|
59
|
-
sdk_yaml_path = File.expand_path('../../template/config/meducation-sdk.yml', __FILE__)
|
60
|
-
begin
|
61
|
-
optional_sdk_yaml_path = "#{sdk_yaml_path}.optional"
|
62
|
-
`cp #{optional_sdk_yaml_path} #{sdk_yaml_path}`
|
63
|
-
Configurator.configure(config_dir: config_dir, logfile: logfile, env: 'production')
|
64
|
-
assert_equal "LarvaSpawn", MeducationSDK.config.access_id
|
65
|
-
assert_equal nil, MeducationSDK.config.secret_key
|
66
|
-
assert_equal Filum.logger, MeducationSDK.config.logger
|
67
|
-
assert_equal nil, MeducationSDK.config.endpoint
|
68
|
-
ensure
|
69
|
-
`rm #{sdk_yaml_path}`
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
30
|
def test_propono_gets_config
|
74
31
|
Configurator.configure(config_dir: config_dir, logfile: logfile)
|
75
32
|
assert_equal "MY-DEV-ACCESS-KEY", Propono.config.access_key
|
data/test/mocker_test.rb
CHANGED
@@ -14,14 +14,6 @@ module Larva
|
|
14
14
|
Mocker.mock!
|
15
15
|
end
|
16
16
|
|
17
|
-
def test_loquor_is_setup
|
18
|
-
Mocker.mock!
|
19
|
-
assert_equal "http://localhost:3000/spi", MeducationSDK.config.endpoint
|
20
|
-
assert_equal "Daemon", MeducationSDK.config.access_id
|
21
|
-
assert_equal "foobar", MeducationSDK.config.secret_key
|
22
|
-
assert_equal Filum.logger, MeducationSDK.config.logger
|
23
|
-
end
|
24
|
-
|
25
17
|
def test_propono_is_configured
|
26
18
|
Mocker.mock!
|
27
19
|
assert_equal Filum.logger, Propono.config.logger
|
data/test/test_helper.rb
CHANGED
@@ -9,31 +9,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
9
9
|
|
10
10
|
require "larva"
|
11
11
|
|
12
|
-
module MeducationSDK
|
13
|
-
def self.config
|
14
|
-
@config ||= Struct.new(:access_id, :secret_key, :endpoint, :logger).new
|
15
|
-
if block_given?
|
16
|
-
yield @config
|
17
|
-
else
|
18
|
-
@config
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
12
|
class Minitest::Test
|
24
|
-
|
25
13
|
def setup
|
26
|
-
Fog.mock!
|
27
14
|
Filum.setup('log/test.log')
|
28
|
-
MeducationSDK.instance_variable_set(:@config, nil)
|
29
|
-
Propono.config do |config|
|
30
|
-
config.access_key = "test-access-key"
|
31
|
-
config.secret_key = "test-secret-key"
|
32
|
-
config.queue_region = "us-east-1"
|
33
|
-
config.application_name = "MyApp"
|
34
|
-
config.queue_suffix = nil
|
35
|
-
|
36
|
-
config.logger = Filum.logger
|
37
|
-
end
|
38
15
|
end
|
39
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: larva
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iHiD
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: propono
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- lib/larva/configuration.rb
|
131
131
|
- lib/larva/configurator.rb
|
132
132
|
- lib/larva/daemon.rb
|
133
|
+
- lib/larva/daemon_creator.rb
|
133
134
|
- lib/larva/listener.rb
|
134
135
|
- lib/larva/message_replayer.rb
|
135
136
|
- lib/larva/mocker.rb
|
@@ -142,16 +143,15 @@ files:
|
|
142
143
|
- template/Rakefile
|
143
144
|
- template/bin/larva_spawn
|
144
145
|
- template/bin/larva_spawn-setup
|
145
|
-
- template/config/meducation-sdk.yml.optional
|
146
146
|
- template/config/propono.yml
|
147
147
|
- template/lib/larva_spawn.rb
|
148
148
|
- template/lib/larva_spawn/configuration.rb
|
149
149
|
- template/lib/larva_spawn/daemon.rb
|
150
150
|
- template/lib/larva_spawn/larva_spawn_error.rb
|
151
|
-
- template/lib/larva_spawn/processors/
|
151
|
+
- template/lib/larva_spawn/processors/user_processor.rb
|
152
152
|
- template/lib/tasks/larva_spawn.rake
|
153
153
|
- template/test/daemon_test.rb
|
154
|
-
- template/test/processors/
|
154
|
+
- template/test/processors/user_processor_test.rb
|
155
155
|
- template/test/test_helper.rb
|
156
156
|
- test/configuration_test.rb
|
157
157
|
- test/configurator_test.rb
|
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
183
|
version: '0'
|
184
184
|
requirements: []
|
185
185
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.
|
186
|
+
rubygems_version: 2.1.9
|
187
187
|
signing_key:
|
188
188
|
specification_version: 4
|
189
189
|
summary: Some Meducation specific helper files for ur pub/sub network
|
@@ -198,3 +198,4 @@ test_files:
|
|
198
198
|
- test/processor_test.rb
|
199
199
|
- test/test_helper.rb
|
200
200
|
- test/worker_pool_test.rb
|
201
|
+
has_rdoc:
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
module LarvaSpawn
|
4
|
-
class MediaFileProcessorTest < Minitest::Test
|
5
|
-
def test_issue_or_update_badges_called_for_correct_message
|
6
|
-
message = { entity: "media_file", action: "processed", media_file_id: 8 }
|
7
|
-
LarvaSpawn::MediaFileProcessor.any_instance.expects(:do_one_thing)
|
8
|
-
LarvaSpawn::MediaFileProcessor.any_instance.expects(:do_another_thing)
|
9
|
-
LarvaSpawn::MediaFileProcessor.process(message)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|