larva 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12c15b7b7bc57f92c91c47d01c62920d97a0be27
4
- data.tar.gz: 1b13eb4986a959ddc4a5d70fc9971dd9738505d2
3
+ metadata.gz: 90a7c92156ab94c08b73eaf6bf10ea13cd067c37
4
+ data.tar.gz: b7f8fb510a0a492d467882e25cb051c4fc46f16d
5
5
  SHA512:
6
- metadata.gz: b713b7c5e6c851c28a25feaed71e7cfee6ab42e0f6fd1fbf0770f06689c139d0186d77ea735aea71a945655298443130bf8055b6d1d10bf752da06ff2d62e3d3
7
- data.tar.gz: 441618eb8034aefe7ece3abaf25a2b3317b75649d01a4ad3884df6bf5daa2dcfeac6202482176a8a3af686216040a1d4f27943da6934d5d19c28b13cf99c757f
6
+ metadata.gz: 70dac2290ba5ae03590e13ba092c01d9b679d17419026487213c8a8e75a61d3d25fde8eac0832ff2bb6ae1cb55692be37a412b6f4294a7275b7b979f9ed0411c
7
+ data.tar.gz: aef52ff82e7f5cdf95c012cd8276360e664a0fa5ad9365bda032dd19e84a1971235a860acffad4bd78fcaab2ff17a27ca4959101b91d5b45fd57caa04fba10ba
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
- # 0.5.0 / 2014-02-22
1
+ # 0.6.0 / 2014-02-23
2
+ * [FEATURE] Add larva binfile.
3
+
4
+ # 0.5.0 / 2014-02-23
2
5
  * [FEATURE] Rely on Propono config for queue suffix.
3
6
  * [FEATURE] Add daemon support.
4
7
  * [FEATURE] Add mocking support.
File without changes
data/bin/larva ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
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
+ end
28
+
29
+ private
30
+
31
+
32
+ def rename_directories
33
+ Dir.glob("#{@daemon_dir}/**/*/").each do |original_path|
34
+ new_path = original_path.gsub('larva_spawn', @daemon_name)
35
+ next if new_path == original_path
36
+
37
+ FileUtils.mv(original_path, new_path)
38
+ rename_directories
39
+ return
40
+ end
41
+ end
42
+
43
+ def rename_files
44
+ Dir.glob("#{@daemon_dir}/**/*").each do |original_path|
45
+ new_path = original_path.gsub('larva_spawn', @daemon_name)
46
+ FileUtils.mv(original_path, new_path) if new_path != original_path
47
+ end
48
+ end
49
+
50
+ def rename_file_contents
51
+ Dir.glob("#{@daemon_dir}/**/*").each do |path|
52
+ next unless File.file?(path)
53
+ contents = File.read(path)
54
+ File.open(path, 'w+') do |file|
55
+ contents.gsub!("LarvaSpawn", @daemon_name.classify)
56
+ contents.gsub!("larva_spawn", @daemon_name)
57
+ file.write(contents)
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ def error_exit(error)
64
+ $stderr.puts "!! Error: #{error}"
65
+ exit
66
+ end
67
+
68
+ error_exit("Please provide a valid command. Valid commands: spawn") unless ARGV[0] == "spawn"
69
+ DaemonCreator.create(ENV["PWD"], ARGV[1])
data/lib/larva/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Larva
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -0,0 +1 @@
1
+ log/
data/template/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'larva', '0.5'
4
+ #gem 'meducation_sdk', '~> 1.0'
5
+
6
+ gem 'rake'
7
+
8
+ group :test do
9
+ gem 'minitest', '~> 5.0.8'
10
+ gem 'mocha', require: false
11
+ end
12
+
@@ -0,0 +1,9 @@
1
+ # LarvaSpawn
2
+
3
+ ## Welcome to your new Daemon.
4
+
5
+ There's a few things you need to do:
6
+
7
+ - If you're using the SDK, uncomment the lines in the `Gemfile` and `test/test_helper.rb`
8
+ - Run `bundle install`
9
+ - Run `bundle exec rake test`
data/template/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'larva_spawn'
6
+
7
+ import "lib/tasks/larva_spawn.rake"
8
+
9
+ require 'rake/testtask'
10
+ Rake::TestTask.new do |t|
11
+ t.pattern = "test/**/*_test.rb"
12
+ end
13
+ task default: :test
@@ -0,0 +1,12 @@
1
+ #!/bin/bash
2
+
3
+ # LOAD CENTRAL RVM PROFILE
4
+ source /etc/profile.d/rvm.sh
5
+
6
+ # SOURCE USER'S RVM MAGIC
7
+ [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
8
+
9
+ # SOURCE APP SPECIFIC ENV VARS
10
+ [[ -e /etc/larva_spawn/larva_spawn-env ]] && source /etc/larva_spawn/larva_spawn-env
11
+
12
+ bundle exec rake larva_spawn:start ENV=production
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+ [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
3
+
4
+ if ! bundle check; then bundle install --deployment; fi
@@ -0,0 +1,6 @@
1
+ development:
2
+ access_id: LarvaSpawn
3
+ secret_key: 'foobar'
4
+
5
+ production:
6
+ access_id: LarvaSpawn
@@ -0,0 +1,13 @@
1
+ development:
2
+ access_key: MY-DEV-ACCESS-KEY
3
+ secret_key: MY-DEV-SECRET-KEY
4
+ region: eu-west-1
5
+ application_name: development_larva_spawn
6
+ queue_suffix:
7
+
8
+ production:
9
+ access_key: MY-PRODUCTION-ACCESS-KEY
10
+ secret_key: MY-PRODUCTION-SECRET-KEY
11
+ region: eu-west-1
12
+ application_name: larva_spawn
13
+ queue_suffix:
@@ -0,0 +1,17 @@
1
+ require 'larva'
2
+ #require 'meducation_sdk'
3
+
4
+ require 'larva_spawn/configuration'
5
+ require 'larva_spawn/larva_spawn_error'
6
+ require 'larva_spawn/daemon'
7
+
8
+ module LarvaSpawn
9
+ def self.config
10
+ @config ||= Configuration.new
11
+ if block_given?
12
+ yield @config
13
+ else
14
+ @config
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module LarvaSpawn
2
+ class Configuration < Larva::Configuration
3
+ end
4
+ end
5
+
@@ -0,0 +1,12 @@
1
+ require 'larva_spawn/processors/media_file_processor'
2
+
3
+ module LarvaSpawn
4
+ class Daemon < Larva::Daemon
5
+ def initialize(options = {})
6
+ processors = {
7
+ media_file: MediaFileProcessor
8
+ }
9
+ super(processors, options)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module LarvaSpawn
2
+ class LarvaSpawnError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,15 @@
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
+
File without changes
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ module LarvaSpawn
4
+ class DaemonTest < Minitest::Test
5
+ def test_the_daemon_starts
6
+ config_dir = File.expand_path('', __FILE__)
7
+ logfile = "log/test.log"
8
+ LarvaSpawn::Daemon.start(config_dir: config_dir, logfile: logfile)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,22 @@
1
+ gem "minitest"
2
+ require "minitest/autorun"
3
+ require "minitest/pride"
4
+ require "minitest/mock"
5
+ require "mocha/setup"
6
+
7
+ unit = File.expand_path('../../test/unit', __FILE__)
8
+ $LOAD_PATH.unshift(unit) unless $LOAD_PATH.include?(unit)
9
+
10
+ lib = File.expand_path('../../lib', __FILE__)
11
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
12
+
13
+ require 'larva_spawn'
14
+
15
+ #MeducationSDK.mock!
16
+
17
+ class Minitest::Test
18
+ def setup
19
+ super
20
+ Larva.mock!
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ description "LarvaSpawn Upstart Script"
2
+ author "Charles Care <charles@meducation.net>"
3
+
4
+ # Triggers
5
+ start on startup
6
+ start on runlevel [2345]
7
+ stop on runlevel [016]
8
+
9
+ # Restart if the service terminates abnormally
10
+ respawn
11
+
12
+ # Give up if the service requires restarting more than 10 times in a 30 second period.
13
+ respawn limit 10 30
14
+
15
+ # Run as a user
16
+ setuid larva_spawn
17
+
18
+ # cwd
19
+ chdir /opt/larva_spawn
20
+
21
+ #pre-start exec su -c /srv/apps/larva_spawn/bin/larva_spawn-setup ec2-user
22
+
23
+ # Run target command
24
+ exec /opt/larva_spawn/bin/larva_spawn
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: larva
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iHiD
@@ -111,7 +111,8 @@ dependencies:
111
111
  description: Meducation helper services for our pub/sub network
112
112
  email:
113
113
  - jeremy@meducation.net
114
- executables: []
114
+ executables:
115
+ - larva
115
116
  extensions: []
116
117
  extra_rdoc_files: []
117
118
  files:
@@ -121,8 +122,9 @@ files:
121
122
  - CONTRIBUTING.md
122
123
  - Gemfile
123
124
  - LICENCE.md
124
- - RAKEFILE
125
125
  - README.md
126
+ - Rakefile
127
+ - bin/larva
126
128
  - larva.gemspec
127
129
  - lib/larva.rb
128
130
  - lib/larva/configuration.rb
@@ -132,6 +134,24 @@ files:
132
134
  - lib/larva/processor.rb
133
135
  - lib/larva/version.rb
134
136
  - lib/larva/worker_pool.rb
137
+ - template/.gitignore
138
+ - template/Gemfile
139
+ - template/README.md
140
+ - template/Rakefile
141
+ - template/bin/larva_spawn
142
+ - template/bin/larva_spawn-setup
143
+ - template/config/meducation-sdk.yml
144
+ - template/config/propono.yml
145
+ - template/lib/larva_spawn.rb
146
+ - template/lib/larva_spawn/configuration.rb
147
+ - template/lib/larva_spawn/daemon.rb
148
+ - template/lib/larva_spawn/larva_spawn_error.rb
149
+ - template/lib/larva_spawn/processors/media_file_processor.rb
150
+ - template/lib/tasks/larva_spawn.rake
151
+ - template/test/daemon_test.rb
152
+ - template/test/processors/media_file_processor_test.rb
153
+ - template/test/test_helper.rb
154
+ - template/upstart/larva_spawn.conf
135
155
  - test/configuration_test.rb
136
156
  - test/daemon_test.rb
137
157
  - test/larva_test.rb