oni 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +4 -0
- data/.travis.yml +23 -0
- data/.yardopts +12 -0
- data/Gemfile +7 -0
- data/LICENSE +19 -0
- data/README.md +170 -0
- data/Rakefile +13 -0
- data/doc/changelog.md +6 -0
- data/doc/css/common.css +69 -0
- data/examples/github_status.rb +75 -0
- data/jenkins.sh +16 -0
- data/lib/oni.rb +7 -1
- data/lib/oni/configurable.rb +107 -0
- data/lib/oni/daemon.rb +190 -0
- data/lib/oni/daemons/sqs.rb +61 -0
- data/lib/oni/mapper.rb +30 -0
- data/lib/oni/version.rb +1 -1
- data/lib/oni/worker.rb +18 -0
- data/oni.gemspec +30 -0
- data/spec/oni/configurable_spec.rb +56 -0
- data/spec/oni/daemon_spec.rb +154 -0
- data/spec/oni/daemons/sqs_spec.rb +31 -0
- data/spec/oni/mapper_spec.rb +25 -0
- data/spec/oni/worker_spec.rb +33 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/simplecov.rb +12 -0
- data/task/coverage.rake +6 -0
- data/task/doc.rake +4 -0
- data/task/jenkins.rake +2 -0
- data/task/tag.rake +6 -0
- data/task/test.rake +4 -0
- metadata +59 -9
@@ -0,0 +1,56 @@
|
|
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
|
@@ -0,0 +1,154 @@
|
|
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 complete(message, output, timings)
|
47
|
+
@message = message
|
48
|
+
@output = output
|
49
|
+
@timings = timings
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
example 'call #after_initialize' do
|
55
|
+
example_daemon.new.number.should == 10
|
56
|
+
end
|
57
|
+
|
58
|
+
example 'call #before_start' do
|
59
|
+
daemon = example_daemon.new
|
60
|
+
daemon.start
|
61
|
+
daemon.stop
|
62
|
+
|
63
|
+
daemon.number2.should == 20
|
64
|
+
end
|
65
|
+
|
66
|
+
example 'raise for the default receive method' do
|
67
|
+
daemon = Oni::Daemon.new
|
68
|
+
|
69
|
+
lambda { daemon.receive }.should raise_error(NotImplementedError)
|
70
|
+
end
|
71
|
+
|
72
|
+
example 'return the amount of threads to use' do
|
73
|
+
example_daemon.set(:threads, 10)
|
74
|
+
|
75
|
+
example_daemon.new.threads.should == 10
|
76
|
+
end
|
77
|
+
|
78
|
+
example 'use the default amount of threads' do
|
79
|
+
example_daemon.set(:threads, nil)
|
80
|
+
|
81
|
+
example_daemon.new.threads.should == Oni::Daemon::DEFAULT_THREAD_AMOUNT
|
82
|
+
end
|
83
|
+
|
84
|
+
example 'create the mapper without any arguments' do
|
85
|
+
mapper = example_daemon.new.create_mapper
|
86
|
+
|
87
|
+
mapper.is_a?(Oni::Mapper).should == true
|
88
|
+
mapper.number.nil?.should == true
|
89
|
+
end
|
90
|
+
|
91
|
+
example 'start and stop the thread daemon' do
|
92
|
+
instance = example_daemon.new
|
93
|
+
instance.start
|
94
|
+
|
95
|
+
instance.workers.length.should == instance.threads
|
96
|
+
|
97
|
+
instance.stop
|
98
|
+
|
99
|
+
instance.workers.length.should == 0
|
100
|
+
end
|
101
|
+
|
102
|
+
example 'process a job' do
|
103
|
+
instance = example_daemon.new
|
104
|
+
|
105
|
+
instance.start
|
106
|
+
instance.stop
|
107
|
+
|
108
|
+
instance.message.should == {:number => 10}
|
109
|
+
instance.output.should == {:new_number => 20}
|
110
|
+
end
|
111
|
+
|
112
|
+
example 'measure the execution time' do
|
113
|
+
instance = example_daemon.new
|
114
|
+
|
115
|
+
instance.start
|
116
|
+
instance.stop
|
117
|
+
|
118
|
+
instance.timings.is_a?(Benchmark::Tms).should == true
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'error handling' do
|
122
|
+
let :example_daemon do
|
123
|
+
Class.new(Oni::Daemon) do
|
124
|
+
set :threads, 0
|
125
|
+
|
126
|
+
def receive
|
127
|
+
yield 10
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
let :custom_error_daemon do
|
133
|
+
Class.new(example_daemon) do
|
134
|
+
set :threads, 0
|
135
|
+
|
136
|
+
def error(error)
|
137
|
+
raise 'custom error'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
example 'should raise by default' do
|
143
|
+
daemon = example_daemon.new
|
144
|
+
|
145
|
+
lambda { daemon.start }.should raise_error(ArgumentError)
|
146
|
+
end
|
147
|
+
|
148
|
+
example 'allow custom error callbacks' do
|
149
|
+
daemon = custom_error_daemon.new
|
150
|
+
|
151
|
+
lambda { daemon.start }.should raise_error(RuntimeError, 'custom error')
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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
|
@@ -0,0 +1,25 @@
|
|
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
|
@@ -0,0 +1,33 @@
|
|
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
|
data/spec/spec_helper.rb
ADDED
data/task/coverage.rake
ADDED
data/task/doc.rake
ADDED
data/task/jenkins.rake
ADDED
data/task/tag.rake
ADDED
data/task/test.rake
ADDED
metadata
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oni
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
-
|
9
|
-
- Wilco van Duinkerken <wilcovanduinkerken@olery.com>
|
7
|
+
- Yorick Peterse
|
8
|
+
- Wilco van Duinkerken
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2013-
|
12
|
+
date: 2013-11-18 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rake
|
@@ -110,16 +109,60 @@ dependencies:
|
|
110
109
|
- - ! '>='
|
111
110
|
- !ruby/object:Gem::Version
|
112
111
|
version: '0'
|
113
|
-
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: aws-sdk
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: Framework for building concurrent daemons in Ruby.
|
114
127
|
email:
|
115
128
|
executables: []
|
116
129
|
extensions: []
|
117
130
|
extra_rdoc_files: []
|
118
131
|
files:
|
132
|
+
- .gitignore
|
133
|
+
- .travis.yml
|
134
|
+
- .yardopts
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- doc/changelog.md
|
140
|
+
- doc/css/common.css
|
141
|
+
- examples/github_status.rb
|
142
|
+
- jenkins.sh
|
119
143
|
- lib/oni.rb
|
144
|
+
- lib/oni/configurable.rb
|
145
|
+
- lib/oni/daemon.rb
|
146
|
+
- lib/oni/daemons/sqs.rb
|
147
|
+
- lib/oni/mapper.rb
|
120
148
|
- lib/oni/version.rb
|
149
|
+
- lib/oni/worker.rb
|
150
|
+
- oni.gemspec
|
151
|
+
- spec/oni/configurable_spec.rb
|
152
|
+
- spec/oni/daemon_spec.rb
|
153
|
+
- spec/oni/daemons/sqs_spec.rb
|
154
|
+
- spec/oni/mapper_spec.rb
|
155
|
+
- spec/oni/worker_spec.rb
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
- spec/support/simplecov.rb
|
158
|
+
- task/coverage.rake
|
159
|
+
- task/doc.rake
|
160
|
+
- task/jenkins.rake
|
161
|
+
- task/tag.rake
|
162
|
+
- task/test.rake
|
121
163
|
homepage:
|
122
|
-
licenses:
|
164
|
+
licenses:
|
165
|
+
- MIT
|
123
166
|
metadata: {}
|
124
167
|
post_install_message:
|
125
168
|
rdoc_options: []
|
@@ -140,6 +183,13 @@ rubyforge_project:
|
|
140
183
|
rubygems_version: 2.1.2
|
141
184
|
signing_key:
|
142
185
|
specification_version: 4
|
143
|
-
summary:
|
144
|
-
test_files:
|
186
|
+
summary: Framework for building concurrent daemons in Ruby.
|
187
|
+
test_files:
|
188
|
+
- spec/oni/configurable_spec.rb
|
189
|
+
- spec/oni/daemon_spec.rb
|
190
|
+
- spec/oni/daemons/sqs_spec.rb
|
191
|
+
- spec/oni/mapper_spec.rb
|
192
|
+
- spec/oni/worker_spec.rb
|
193
|
+
- spec/spec_helper.rb
|
194
|
+
- spec/support/simplecov.rb
|
145
195
|
has_rdoc: yard
|