larva 0.9.2 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d881b296762829b1231faf641557de3f07fd026
4
- data.tar.gz: 7f5e4c25ef8b107f6a321e7d7fa8cdac5874901c
3
+ metadata.gz: 56edc62f830f8beaa3862dcb8ff381f1cd4b35d2
4
+ data.tar.gz: 7a77450848d9d87cb6b50f9ac95486cce0fdd8c5
5
5
  SHA512:
6
- metadata.gz: 591e77b84ca81e4df51cd338982d869486ccbef30d61bc9fc0027cf3f9521858263554786dba168939a33ae36eadb3cd860fa1837ca18f1cd364359c82ab0222
7
- data.tar.gz: 7e178491832e605929b2d9a8d279bfc9a912327d369eef11d09b4b6677ed907b36a3acc5118b5d42a1854fc78a11578483f9ba05905b7265fbfb00c8654f97b1
6
+ metadata.gz: 330518dec7552c9150b65fa6ae78c7f12283da832344be782f4db5a48c3795aee8463cdb2f3809f78dc3d260269467fb43604fe06b204d64421c5009697ec923
7
+ data.tar.gz: b928a17b94ce057fd544c39824dfe9be8fcdabbdd72c97b070210ce30339de611cb0d271fe64f2544eff418c9e915109b45ee8a9e2d291b12ac5d08a0827fb71
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 1.0.0 / 2014-07-12
2
+ * [FEATURE] Remove Meducation specific code and bump to 1.0.0
3
+
1
4
  # 0.9.2 / 2014-04-30
2
5
  * [BIGFIX] Do not add suffix to queue names - added by Propono.
3
6
 
data/bin/larva CHANGED
@@ -1,70 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'fileutils'
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
- require 'larva/configuration'
6
- require 'larva/configurator'
7
- require 'larva/mocker'
8
- require 'larva/listener'
9
- require 'larva/processor'
10
- require 'larva/worker_pool'
11
- require 'larva/daemon'
12
- require 'larva/message_replayer'
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
@@ -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
@@ -9,7 +9,6 @@ module Larva
9
9
 
10
10
  # Allowed Options:
11
11
  # :env - Defaults to development
12
- # :meducation_sdk_secret_key - Defauls to looking in config file
13
12
  def initialize(processors, options = {})
14
13
  @processors = processors
15
14
  @options = options
@@ -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
- puts "Message : #{sqs_message}"
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
@@ -1,3 +1,3 @@
1
1
  module Larva
2
- VERSION = '0.9.2'
2
+ VERSION = '1.0.0'
3
3
  end
data/template/Gemfile CHANGED
@@ -1,8 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'larva'
4
- #gem 'meducation_sdk', '~> 1.0'
5
-
6
4
  gem 'rake'
7
5
 
8
6
  group :test do
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/*`
@@ -1,5 +1,4 @@
1
1
  require 'larva'
2
- #require 'meducation_sdk'
3
2
 
4
3
  require 'larva_spawn/configuration'
5
4
  require 'larva_spawn/larva_spawn_error'
@@ -1,10 +1,10 @@
1
- require 'larva_spawn/processors/media_file_processor'
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
- media_file: MediaFileProcessor
7
+ user: UserProcessor
8
8
  }
9
9
  super(processors, options)
10
10
  end
@@ -0,0 +1,12 @@
1
+ module LarvaSpawn
2
+ class UserProcessor < Larva::Processor
3
+ def user_created
4
+ do_something(message[:foo])
5
+ end
6
+
7
+ private
8
+ def do_something(foo)
9
+ end
10
+ end
11
+ end
12
+
@@ -3,7 +3,6 @@ namespace :larva_spawn do
3
3
  config_dir = File.expand_path('../../../config', __FILE__)
4
4
  logfile = "./log/larva_spawn.log"
5
5
  options = {
6
- meducation_sdk_secret_key: ENV['LARVA_SPAWN_API_KEY'],
7
6
  env: ENV['ENV'],
8
7
  config_dir: config_dir,
9
8
  logfile: logfile
@@ -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
@@ -12,8 +12,6 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
12
12
 
13
13
  require 'larva_spawn'
14
14
 
15
- #MeducationSDK.mock!
16
-
17
15
  class Minitest::Test
18
16
  def setup
19
17
  super
@@ -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.9.2
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-06-09 00:00:00.000000000 Z
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/media_file_processor.rb
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/media_file_processor_test.rb
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.2.1
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,6 +0,0 @@
1
- development:
2
- access_id: LarvaSpawn
3
- secret_key: 'foobar'
4
-
5
- production:
6
- access_id: LarvaSpawn
@@ -1,15 +0,0 @@
1
- module LarvaSpawn
2
- class MediaFileProcessor < Larva::Processor
3
- def media_file_processed
4
- do_one_thing
5
- do_another_thing
6
- end
7
-
8
- private
9
- def do_one_thing
10
- end
11
- def do_another_thing
12
- end
13
- end
14
- end
15
-
@@ -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