oni 3.2.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/oni.rb +0 -1
- data/lib/oni/daemon.rb +5 -13
- data/lib/oni/daemons/sqs.rb +13 -5
- data/lib/oni/version.rb +1 -1
- data/oni.gemspec +9 -4
- metadata +10 -37
- data/.gitignore +0 -14
- data/.travis.yml +0 -23
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -54
- data/Rakefile +0 -12
- data/examples/github_status.rb +0 -75
- data/jenkins.sh +0 -16
- data/spec/oni/configurable_spec.rb +0 -56
- data/spec/oni/daemon_spec.rb +0 -158
- data/spec/oni/daemons/sqs_spec.rb +0 -31
- data/spec/oni/mapper_spec.rb +0 -25
- data/spec/oni/worker_spec.rb +0 -33
- data/spec/oni/wrapped_error_spec.rb +0 -44
- data/spec/spec_helper.rb +0 -16
- data/spec/support/simplecov.rb +0 -12
- data/task/coverage.rake +0 -6
- data/task/doc.rake +0 -4
- data/task/jenkins.rake +0 -2
- data/task/tag.rake +0 -6
- data/task/test.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e86f0fc6b0d6056128511d7a55a0d6be22b4830a
|
4
|
+
data.tar.gz: 67bb84f5831cfcaa771103bfa81e5bc96c052054
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3da0297aec49385fe97d280906ef75dc89f24e0c571baab7ebc3dde484e13ea31e47f0b7dd80928dfd5da8b0d4adab10d3a8aa33b30daa63e5872f38dfac6b7c
|
7
|
+
data.tar.gz: ca0126f07de0d95b51e5abc149435450c573672352b7525b2acabbba010d812fa17e83736828bf98706515d40b568e21b1c5c66d4e908425c77a23203214199a
|
data/README.md
CHANGED
@@ -138,17 +138,17 @@ Basic usage of Oni is as following:
|
|
138
138
|
end
|
139
139
|
|
140
140
|
# This would get executed upon completion of a job.
|
141
|
-
def complete(message, result
|
141
|
+
def complete(message, result)
|
142
142
|
puts result
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
146
|
class MyMapper < Oni::Mapper
|
147
147
|
# Map the input given by MyDaemon#receive into the right arguments
|
148
|
-
# for MyWorker#initialize.
|
148
|
+
# for MyWorker#initialize.
|
149
149
|
#
|
150
|
-
# NOTE: the return value should be an Array.
|
151
|
-
# Oni calls #to_a on the output (more specifically we use a splat) so your
|
150
|
+
# NOTE: the return value should be an Array.
|
151
|
+
# Oni calls #to_a on the output (more specifically we use a splat) so your
|
152
152
|
# return value should be an Array. If you do not return an Array you risk
|
153
153
|
# that the object you return will wrongfully be converted into an Array.
|
154
154
|
# This is painful when it comes to Hashes, which, after the #to_a call
|
data/lib/oni.rb
CHANGED
data/lib/oni/daemon.rb
CHANGED
@@ -82,12 +82,9 @@ module Oni
|
|
82
82
|
# @param [Mixed] message
|
83
83
|
#
|
84
84
|
def process(message)
|
85
|
-
output
|
86
|
-
timings = Benchmark.measure do
|
87
|
-
output = run_worker(message)
|
88
|
-
end
|
85
|
+
output = run_worker(message)
|
89
86
|
|
90
|
-
complete(message, output
|
87
|
+
complete(message, output)
|
91
88
|
end
|
92
89
|
|
93
90
|
##
|
@@ -101,9 +98,7 @@ module Oni
|
|
101
98
|
mapper = create_mapper
|
102
99
|
input = mapper.map_input(message)
|
103
100
|
worker = option(:worker).new(*input)
|
104
|
-
output =
|
105
|
-
worker.process
|
106
|
-
end
|
101
|
+
output = worker.process
|
107
102
|
|
108
103
|
return mapper.map_output(output)
|
109
104
|
end
|
@@ -119,18 +114,15 @@ module Oni
|
|
119
114
|
|
120
115
|
##
|
121
116
|
# Called when a job has been completed, by default this method is a noop.
|
122
|
-
# This method is passed
|
117
|
+
# This method is passed 2 arguments:
|
123
118
|
#
|
124
119
|
# 1. The raw input message.
|
125
120
|
# 2. The output of the worker (remapped by the mapper).
|
126
|
-
# 3. A Benchmark::Tms instance that contains the timings for processing the
|
127
|
-
# message.
|
128
121
|
#
|
129
122
|
# @param [Mixed] message The raw input message (e.g. an AWS SQS message)
|
130
123
|
# @param [Mixed] output The output of the worker.
|
131
|
-
# @param [Benchmark::Tms] timings
|
132
124
|
#
|
133
|
-
def complete(message, output
|
125
|
+
def complete(message, output)
|
134
126
|
end
|
135
127
|
|
136
128
|
##
|
data/lib/oni/daemons/sqs.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'aws-sdk
|
1
|
+
require 'aws-sdk'
|
2
2
|
|
3
3
|
module Oni
|
4
4
|
module Daemons
|
@@ -49,13 +49,21 @@ module Oni
|
|
49
49
|
##
|
50
50
|
# Returns the queue to use for the current thread.
|
51
51
|
#
|
52
|
-
# @return [
|
52
|
+
# @return [Aws::SQS::QueuePoller]
|
53
53
|
#
|
54
|
-
#:nocov:
|
55
54
|
def queue
|
56
|
-
return
|
55
|
+
return Aws::SQS::QueuePoller.new(queue_url)
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# @return [String]
|
60
|
+
#
|
61
|
+
def queue_url
|
62
|
+
sqs = Aws::SQS::Client.new
|
63
|
+
response = sqs.get_queue_url(:queue_name => option(:queue_name))
|
64
|
+
|
65
|
+
return response.queue_url
|
57
66
|
end
|
58
|
-
#:nocov:
|
59
67
|
end # SQS
|
60
68
|
end # Daemons
|
61
69
|
end # Oni
|
data/lib/oni/version.rb
CHANGED
data/oni.gemspec
CHANGED
@@ -15,9 +15,14 @@ Gem::Specification.new do |gem|
|
|
15
15
|
|
16
16
|
gem.required_ruby_version = '>= 1.9.3'
|
17
17
|
|
18
|
-
gem.files
|
19
|
-
|
20
|
-
|
18
|
+
gem.files = Dir.glob([
|
19
|
+
'doc/**/*',
|
20
|
+
'lib/**/*.rb',
|
21
|
+
'README.md',
|
22
|
+
'LICENSE',
|
23
|
+
'oni.gemspec',
|
24
|
+
'.yardopts'
|
25
|
+
]).select { |file| File.file?(file) }
|
21
26
|
|
22
27
|
gem.add_development_dependency 'rake'
|
23
28
|
gem.add_development_dependency 'bundler'
|
@@ -25,5 +30,5 @@ Gem::Specification.new do |gem|
|
|
25
30
|
gem.add_development_dependency 'yard'
|
26
31
|
gem.add_development_dependency 'simplecov'
|
27
32
|
gem.add_development_dependency 'kramdown'
|
28
|
-
gem.add_development_dependency 'aws-sdk
|
33
|
+
gem.add_development_dependency 'aws-sdk', '~> 2.0'
|
29
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oni
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yorick Peterse
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -96,37 +96,30 @@ dependencies:
|
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
name: aws-sdk
|
99
|
+
name: aws-sdk
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - "
|
102
|
+
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '0'
|
104
|
+
version: '2.0'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - "
|
109
|
+
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: '0'
|
111
|
+
version: '2.0'
|
112
112
|
description: Framework for building concurrent daemons in Ruby.
|
113
113
|
email:
|
114
114
|
executables: []
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- ".gitignore"
|
119
|
-
- ".travis.yml"
|
120
118
|
- ".yardopts"
|
121
|
-
- Gemfile
|
122
|
-
- Gemfile.lock
|
123
119
|
- LICENSE
|
124
120
|
- README.md
|
125
|
-
- Rakefile
|
126
121
|
- doc/changelog.md
|
127
122
|
- doc/css/common.css
|
128
|
-
- examples/github_status.rb
|
129
|
-
- jenkins.sh
|
130
123
|
- lib/oni.rb
|
131
124
|
- lib/oni/configurable.rb
|
132
125
|
- lib/oni/daemon.rb
|
@@ -136,19 +129,6 @@ files:
|
|
136
129
|
- lib/oni/worker.rb
|
137
130
|
- lib/oni/wrapped_error.rb
|
138
131
|
- oni.gemspec
|
139
|
-
- spec/oni/configurable_spec.rb
|
140
|
-
- spec/oni/daemon_spec.rb
|
141
|
-
- spec/oni/daemons/sqs_spec.rb
|
142
|
-
- spec/oni/mapper_spec.rb
|
143
|
-
- spec/oni/worker_spec.rb
|
144
|
-
- spec/oni/wrapped_error_spec.rb
|
145
|
-
- spec/spec_helper.rb
|
146
|
-
- spec/support/simplecov.rb
|
147
|
-
- task/coverage.rake
|
148
|
-
- task/doc.rake
|
149
|
-
- task/jenkins.rake
|
150
|
-
- task/tag.rake
|
151
|
-
- task/test.rake
|
152
132
|
homepage:
|
153
133
|
licenses:
|
154
134
|
- MIT
|
@@ -169,16 +149,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
149
|
version: '0'
|
170
150
|
requirements: []
|
171
151
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.4.5
|
173
153
|
signing_key:
|
174
154
|
specification_version: 4
|
175
155
|
summary: Framework for building concurrent daemons in Ruby.
|
176
|
-
test_files:
|
177
|
-
|
178
|
-
- spec/oni/daemon_spec.rb
|
179
|
-
- spec/oni/daemons/sqs_spec.rb
|
180
|
-
- spec/oni/mapper_spec.rb
|
181
|
-
- spec/oni/worker_spec.rb
|
182
|
-
- spec/oni/wrapped_error_spec.rb
|
183
|
-
- spec/spec_helper.rb
|
184
|
-
- spec/support/simplecov.rb
|
156
|
+
test_files: []
|
157
|
+
has_rdoc: yard
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
---
|
2
|
-
script: bundle exec rake
|
3
|
-
|
4
|
-
rvm:
|
5
|
-
- 1.9.3
|
6
|
-
- 2.0
|
7
|
-
- 2.1
|
8
|
-
- jruby
|
9
|
-
- rbx-2.2
|
10
|
-
|
11
|
-
notifications:
|
12
|
-
email:
|
13
|
-
recipients:
|
14
|
-
- development@olery.com
|
15
|
-
email:
|
16
|
-
on_success: change
|
17
|
-
on_failure: change
|
18
|
-
|
19
|
-
branches:
|
20
|
-
only:
|
21
|
-
- master
|
22
|
-
|
23
|
-
#cache: bundler
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
oni (3.1.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
aws-sdk-v1 (1.67.0)
|
10
|
-
json (~> 1.4)
|
11
|
-
nokogiri (~> 1)
|
12
|
-
diff-lcs (1.3)
|
13
|
-
docile (1.1.5)
|
14
|
-
json (1.8.6)
|
15
|
-
kramdown (1.15.0)
|
16
|
-
mini_portile2 (2.3.0)
|
17
|
-
nokogiri (1.8.1)
|
18
|
-
mini_portile2 (~> 2.3.0)
|
19
|
-
rake (12.1.0)
|
20
|
-
rspec (3.6.0)
|
21
|
-
rspec-core (~> 3.6.0)
|
22
|
-
rspec-expectations (~> 3.6.0)
|
23
|
-
rspec-mocks (~> 3.6.0)
|
24
|
-
rspec-core (3.6.0)
|
25
|
-
rspec-support (~> 3.6.0)
|
26
|
-
rspec-expectations (3.6.0)
|
27
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.6.0)
|
29
|
-
rspec-mocks (3.6.0)
|
30
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.6.0)
|
32
|
-
rspec-support (3.6.0)
|
33
|
-
simplecov (0.15.1)
|
34
|
-
docile (~> 1.1.0)
|
35
|
-
json (>= 1.8, < 3)
|
36
|
-
simplecov-html (~> 0.10.0)
|
37
|
-
simplecov-html (0.10.2)
|
38
|
-
yard (0.9.9)
|
39
|
-
|
40
|
-
PLATFORMS
|
41
|
-
ruby
|
42
|
-
|
43
|
-
DEPENDENCIES
|
44
|
-
aws-sdk-v1
|
45
|
-
bundler
|
46
|
-
kramdown
|
47
|
-
oni!
|
48
|
-
rake
|
49
|
-
rspec (~> 3.0)
|
50
|
-
simplecov
|
51
|
-
yard
|
52
|
-
|
53
|
-
BUNDLED WITH
|
54
|
-
1.15.4
|
data/Rakefile
DELETED
data/examples/github_status.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
require_relative '../lib/oni'
|
2
|
-
require 'net/https'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
module GithubStatus
|
6
|
-
class Mapper < Oni::Mapper
|
7
|
-
def map_input(input)
|
8
|
-
return input['url']
|
9
|
-
end
|
10
|
-
|
11
|
-
def map_output(output)
|
12
|
-
return output['status']
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class Worker < Oni::Worker
|
17
|
-
attr_reader :url
|
18
|
-
|
19
|
-
def initialize(url)
|
20
|
-
@url = url
|
21
|
-
end
|
22
|
-
|
23
|
-
def process
|
24
|
-
uri_object = URI.parse(url)
|
25
|
-
http = Net::HTTP.new(uri_object.host, uri_object.port)
|
26
|
-
http.use_ssl = true
|
27
|
-
request = Net::HTTP::Get.new(uri_object.request_uri)
|
28
|
-
response = http.request(request)
|
29
|
-
|
30
|
-
return JSON(response.body)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Daemon < Oni::Daemon
|
35
|
-
# Check GitHub every 10 minutes.
|
36
|
-
set :interval, 600
|
37
|
-
|
38
|
-
# Since this daemon does the same thing over and over we'll only run 1
|
39
|
-
# thread instead of multiple ones.
|
40
|
-
set :threads, 1
|
41
|
-
|
42
|
-
# The URL to check.
|
43
|
-
set :status_url, 'https://status.github.com/api/status.json'
|
44
|
-
|
45
|
-
set :mapper, Mapper
|
46
|
-
set :worker, Worker
|
47
|
-
|
48
|
-
def receive
|
49
|
-
loop do
|
50
|
-
# This is to mimic some kind of job coming from a queue.
|
51
|
-
yield({'url' => option(:status_url)})
|
52
|
-
|
53
|
-
sleep(option(:interval))
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def complete(message, output, timings)
|
58
|
-
sec = timings.real.round(3)
|
59
|
-
|
60
|
-
puts "GitHub status: #{output}, retrieved in #{sec} seconds"
|
61
|
-
end
|
62
|
-
end # Daemon
|
63
|
-
end # GithubStatus
|
64
|
-
|
65
|
-
daemon = GithubStatus::Daemon.new
|
66
|
-
|
67
|
-
%w{INT TERM}.each do |signal|
|
68
|
-
trap(signal) do
|
69
|
-
puts 'Shutting down...'
|
70
|
-
|
71
|
-
daemon.stop
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
daemon.start
|
data/jenkins.sh
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# This configuration file is used to test/build the project on Olery's private
|
2
|
-
# Jenkins instance. Patches containing changes to this file made by people
|
3
|
-
# outside of Olery will most likely be rejected.
|
4
|
-
|
5
|
-
# The name of the project, used for other settings such as the MySQL database
|
6
|
-
# and the package name.
|
7
|
-
PROJECT_NAME="oni"
|
8
|
-
|
9
|
-
# Whether or not to use a MySQL database, set to a non empty value to enable
|
10
|
-
# this. Enabling this will tell Jenkins to create/drop the database and to
|
11
|
-
# import any migrations if needed.
|
12
|
-
unset USE_MYSQL
|
13
|
-
|
14
|
-
# The command to run for the test suite. Junction itself doesn't have a test
|
15
|
-
# suite so we'll use a noop.
|
16
|
-
TEST_COMMAND="rake jenkins --trace"
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Oni::Configurable do
|
4
|
-
let :example_class do
|
5
|
-
Class.new do
|
6
|
-
include Oni::Configurable
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
example 'setting an option' do
|
11
|
-
example_class.set(:number, 10)
|
12
|
-
|
13
|
-
example_class.options[:number].should == 10
|
14
|
-
end
|
15
|
-
|
16
|
-
example 'setting multiple options' do
|
17
|
-
example_class.set_multiple(:a => 10, :b => 20)
|
18
|
-
|
19
|
-
example_class.options[:a].should == 10
|
20
|
-
example_class.options[:b].should == 20
|
21
|
-
end
|
22
|
-
|
23
|
-
example 'retrieve an option' do
|
24
|
-
example_class.set(:number, 10)
|
25
|
-
|
26
|
-
example_class.new.option(:number).should == 10
|
27
|
-
end
|
28
|
-
|
29
|
-
example 'retrieve an option with a default value' do
|
30
|
-
example_class.new.option(:number, 20).should == 20
|
31
|
-
end
|
32
|
-
|
33
|
-
example 'evaluate an option value upon retrieval' do
|
34
|
-
example_class.set(:dynamic, proc { Struct.new(:example) })
|
35
|
-
|
36
|
-
instance = example_class.new
|
37
|
-
|
38
|
-
instance.option(:dynamic).should_not == instance.option(:dynamic)
|
39
|
-
end
|
40
|
-
|
41
|
-
example 'raise for a required but unset option' do
|
42
|
-
instance = example_class.new
|
43
|
-
block = lambda { instance.require_option!(:another_number) }
|
44
|
-
|
45
|
-
block.should raise_error(ArgumentError)
|
46
|
-
end
|
47
|
-
|
48
|
-
example 'do not raise for a required option with a value' do
|
49
|
-
example_class.set(:another_number, 20)
|
50
|
-
|
51
|
-
instance = example_class.new
|
52
|
-
|
53
|
-
instance.require_option!(:another_number)
|
54
|
-
instance.option(:another_number).should == 20
|
55
|
-
end
|
56
|
-
end
|
data/spec/oni/daemon_spec.rb
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Oni::Daemon do
|
4
|
-
let :example_daemon do
|
5
|
-
mapper = Class.new(Oni::Mapper) do
|
6
|
-
attr_reader :number
|
7
|
-
|
8
|
-
def map_input(input)
|
9
|
-
return input[:number]
|
10
|
-
end
|
11
|
-
|
12
|
-
def map_output(number)
|
13
|
-
return {:new_number => number}
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
worker = Class.new(Oni::Worker) do
|
18
|
-
def initialize(number)
|
19
|
-
@number = number
|
20
|
-
end
|
21
|
-
|
22
|
-
def process
|
23
|
-
return @number * 2
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
Class.new(Oni::Daemon) do
|
28
|
-
attr_reader :number, :number2, :message, :output, :timings
|
29
|
-
|
30
|
-
set :mapper, mapper
|
31
|
-
set :worker, worker
|
32
|
-
set :threads, 2
|
33
|
-
|
34
|
-
def after_initialize
|
35
|
-
@number = 10
|
36
|
-
end
|
37
|
-
|
38
|
-
def before_start
|
39
|
-
@number2 = 20
|
40
|
-
end
|
41
|
-
|
42
|
-
def receive
|
43
|
-
yield({:number => 10})
|
44
|
-
end
|
45
|
-
|
46
|
-
def error(error, extra_data = nil)
|
47
|
-
raise "#{error.message}: #{extra_data}"
|
48
|
-
end
|
49
|
-
|
50
|
-
def complete(message, output, timings)
|
51
|
-
@message = message
|
52
|
-
@output = output
|
53
|
-
@timings = timings
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
example 'call #after_initialize' do
|
59
|
-
example_daemon.new.number.should == 10
|
60
|
-
end
|
61
|
-
|
62
|
-
example 'call #before_start' do
|
63
|
-
daemon = example_daemon.new
|
64
|
-
daemon.start
|
65
|
-
daemon.stop
|
66
|
-
|
67
|
-
daemon.number2.should == 20
|
68
|
-
end
|
69
|
-
|
70
|
-
example 'raise for the default receive method' do
|
71
|
-
daemon = Oni::Daemon.new
|
72
|
-
|
73
|
-
lambda { daemon.receive }.should raise_error(NotImplementedError)
|
74
|
-
end
|
75
|
-
|
76
|
-
example 'return the amount of threads to use' do
|
77
|
-
example_daemon.set(:threads, 10)
|
78
|
-
|
79
|
-
example_daemon.new.threads.should == 10
|
80
|
-
end
|
81
|
-
|
82
|
-
example 'use the default amount of threads' do
|
83
|
-
example_daemon.set(:threads, nil)
|
84
|
-
|
85
|
-
example_daemon.new.threads.should == Oni::Daemon::DEFAULT_THREAD_AMOUNT
|
86
|
-
end
|
87
|
-
|
88
|
-
example 'create the mapper without any arguments' do
|
89
|
-
mapper = example_daemon.new.create_mapper
|
90
|
-
|
91
|
-
mapper.is_a?(Oni::Mapper).should == true
|
92
|
-
mapper.number.nil?.should == true
|
93
|
-
end
|
94
|
-
|
95
|
-
example 'start and stop the thread daemon' do
|
96
|
-
instance = example_daemon.new
|
97
|
-
instance.start
|
98
|
-
|
99
|
-
instance.workers.length.should == instance.threads
|
100
|
-
|
101
|
-
instance.stop
|
102
|
-
|
103
|
-
instance.workers.length.should == 0
|
104
|
-
end
|
105
|
-
|
106
|
-
example 'process a job' do
|
107
|
-
instance = example_daemon.new
|
108
|
-
|
109
|
-
instance.start
|
110
|
-
instance.stop
|
111
|
-
|
112
|
-
instance.message.should == {:number => 10}
|
113
|
-
instance.output.should == {:new_number => 20}
|
114
|
-
end
|
115
|
-
|
116
|
-
example 'measure the execution time' do
|
117
|
-
instance = example_daemon.new
|
118
|
-
|
119
|
-
instance.start
|
120
|
-
instance.stop
|
121
|
-
|
122
|
-
instance.timings.is_a?(Benchmark::Tms).should == true
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'error handling' do
|
126
|
-
let :example_daemon do
|
127
|
-
Class.new(Oni::Daemon) do
|
128
|
-
set :threads, 0
|
129
|
-
|
130
|
-
def receive
|
131
|
-
yield 10
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
let :custom_error_daemon do
|
137
|
-
Class.new(example_daemon) do
|
138
|
-
set :threads, 0
|
139
|
-
|
140
|
-
def error(error, extra_data = nil)
|
141
|
-
raise 'custom error'
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
example 'should raise by default' do
|
147
|
-
daemon = example_daemon.new
|
148
|
-
|
149
|
-
lambda { daemon.start }.should raise_error(ArgumentError)
|
150
|
-
end
|
151
|
-
|
152
|
-
example 'allow custom error callbacks' do
|
153
|
-
daemon = custom_error_daemon.new
|
154
|
-
|
155
|
-
lambda { daemon.start }.should raise_error(RuntimeError, 'custom error')
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require_relative '../../../lib/oni/daemons/sqs'
|
3
|
-
|
4
|
-
describe Oni::Daemons::SQS do
|
5
|
-
let :example_daemon do
|
6
|
-
Class.new(Oni::Daemons::SQS)
|
7
|
-
end
|
8
|
-
|
9
|
-
example 'require the queue name to be set' do
|
10
|
-
block = lambda { example_daemon.new }
|
11
|
-
|
12
|
-
block.should raise_error(ArgumentError, /The option queue_name is required/)
|
13
|
-
end
|
14
|
-
|
15
|
-
example 'receive a message' do
|
16
|
-
example_daemon.set(:queue_name, 'example')
|
17
|
-
|
18
|
-
instance = example_daemon.new
|
19
|
-
queue = Class.new do
|
20
|
-
def poll(options = {})
|
21
|
-
yield 10
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
instance.stub(:queue).and_return(queue.new)
|
26
|
-
|
27
|
-
instance.receive do |number|
|
28
|
-
number.should == 10
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/spec/oni/mapper_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Oni::Mapper do
|
4
|
-
let :example_mapper do
|
5
|
-
Class.new(Oni::Mapper)
|
6
|
-
end
|
7
|
-
|
8
|
-
example 'set an option of the class' do
|
9
|
-
example_mapper.set(:number, 10)
|
10
|
-
|
11
|
-
example_mapper.new.option(:number).should == 10
|
12
|
-
end
|
13
|
-
|
14
|
-
example 'return the raw input' do
|
15
|
-
input = {:number => 10}
|
16
|
-
|
17
|
-
example_mapper.new.map_input(input).should == input
|
18
|
-
end
|
19
|
-
|
20
|
-
example 'return the raw output' do
|
21
|
-
output = {:number => 10}
|
22
|
-
|
23
|
-
example_mapper.new.map_output(output).should == output
|
24
|
-
end
|
25
|
-
end
|
data/spec/oni/worker_spec.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Oni::Worker do
|
4
|
-
let :example_worker do
|
5
|
-
Class.new(Oni::Worker) do
|
6
|
-
def initialize(number = 10)
|
7
|
-
@number = number
|
8
|
-
end
|
9
|
-
|
10
|
-
def process
|
11
|
-
return @number * 2
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
example 'raise for the default process method' do
|
17
|
-
worker = Oni::Worker.new
|
18
|
-
|
19
|
-
lambda { worker.process }.should raise_error(NotImplementedError)
|
20
|
-
end
|
21
|
-
|
22
|
-
example 'set an option of the class' do
|
23
|
-
example_worker.set(:number, 10)
|
24
|
-
|
25
|
-
example_worker.new.option(:number).should == 10
|
26
|
-
end
|
27
|
-
|
28
|
-
example 'process a job' do
|
29
|
-
worker = example_worker.new(10)
|
30
|
-
|
31
|
-
worker.process.should == 20
|
32
|
-
end
|
33
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Oni::WrappedError do
|
4
|
-
before do
|
5
|
-
@original_error = StandardError.new('Hello world')
|
6
|
-
@parameters = {:foo => :bar}
|
7
|
-
end
|
8
|
-
|
9
|
-
context 'manually creating instances' do
|
10
|
-
example 'set the message' do
|
11
|
-
Oni::WrappedError.new('foo').message.should == 'foo'
|
12
|
-
end
|
13
|
-
|
14
|
-
example 'set the original error' do
|
15
|
-
error = Oni::WrappedError.new('foo', :original_error => @original_error)
|
16
|
-
|
17
|
-
error.original_error.should == @original_error
|
18
|
-
end
|
19
|
-
|
20
|
-
example 'set the parameters' do
|
21
|
-
error = Oni::WrappedError.new('foo', :parameters => @parameters)
|
22
|
-
|
23
|
-
error.parameters.should == @parameters
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'creating instances from other errors' do
|
28
|
-
before do
|
29
|
-
@error = Oni::WrappedError.from(@original_error, @parameters)
|
30
|
-
end
|
31
|
-
|
32
|
-
example 'set the message' do
|
33
|
-
@error.message.should == @original_error.message
|
34
|
-
end
|
35
|
-
|
36
|
-
example 'set the original error' do
|
37
|
-
@error.original_error.should == @original_error
|
38
|
-
end
|
39
|
-
|
40
|
-
example 'set the parameters' do
|
41
|
-
@error.parameters.should == @parameters
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
|
3
|
-
require_relative 'support/simplecov' if ENV['COVERAGE']
|
4
|
-
require_relative '../lib/oni'
|
5
|
-
|
6
|
-
RSpec.configure do |config|
|
7
|
-
config.color = true
|
8
|
-
|
9
|
-
config.expect_with :rspec do |c|
|
10
|
-
c.syntax = [:should, :expect]
|
11
|
-
end
|
12
|
-
|
13
|
-
config.mock_with :rspec do |c|
|
14
|
-
c.syntax = [:should, :expect]
|
15
|
-
end
|
16
|
-
end
|
data/spec/support/simplecov.rb
DELETED
data/task/coverage.rake
DELETED
data/task/doc.rake
DELETED
data/task/jenkins.rake
DELETED
data/task/tag.rake
DELETED
data/task/test.rake
DELETED