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 +4 -4
- data/CHANGELOG.md +4 -1
- data/{RAKEFILE → Rakefile} +0 -0
- data/bin/larva +69 -0
- data/lib/larva/version.rb +1 -1
- data/template/.gitignore +1 -0
- data/template/Gemfile +12 -0
- data/template/README.md +9 -0
- data/template/Rakefile +13 -0
- data/template/bin/larva_spawn +12 -0
- data/template/bin/larva_spawn-setup +4 -0
- data/template/config/meducation-sdk.yml +6 -0
- data/template/config/propono.yml +13 -0
- data/template/lib/larva_spawn.rb +17 -0
- data/template/lib/larva_spawn/configuration.rb +5 -0
- data/template/lib/larva_spawn/daemon.rb +12 -0
- data/template/lib/larva_spawn/larva_spawn_error.rb +4 -0
- data/template/lib/larva_spawn/processors/media_file_processor.rb +15 -0
- data/template/lib/tasks/larva_spawn.rake +0 -0
- data/template/test/daemon_test.rb +11 -0
- data/template/test/processors/media_file_processor_test.rb +12 -0
- data/template/test/test_helper.rb +22 -0
- data/template/upstart/larva_spawn.conf +24 -0
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90a7c92156ab94c08b73eaf6bf10ea13cd067c37
|
4
|
+
data.tar.gz: b7f8fb510a0a492d467882e25cb051c4fc46f16d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70dac2290ba5ae03590e13ba092c01d9b679d17419026487213c8a8e75a61d3d25fde8eac0832ff2bb6ae1cb55692be37a412b6f4294a7275b7b979f9ed0411c
|
7
|
+
data.tar.gz: aef52ff82e7f5cdf95c012cd8276360e664a0fa5ad9365bda032dd19e84a1971235a860acffad4bd78fcaab2ff17a27ca4959101b91d5b45fd57caa04fba10ba
|
data/CHANGELOG.md
CHANGED
data/{RAKEFILE → Rakefile}
RENAMED
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
data/template/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
log/
|
data/template/Gemfile
ADDED
data/template/README.md
ADDED
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,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
|
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.
|
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
|