helpstation 0.1.4 → 0.1.5
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 +4 -4
- data/.travis.yml +7 -0
- data/lib/helpstation.rb +2 -0
- data/lib/helpstation/evaluator.rb +2 -2
- data/lib/helpstation/processors.rb +47 -0
- data/lib/helpstation/version.rb +1 -1
- data/spec/helpstation/evaluator_spec.rb +27 -0
- data/spec/helpstation/{processors → fetchers}/by_key_fetcher_spec.rb +0 -0
- data/spec/helpstation/processors/parallel_processor_spec.rb +71 -0
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bc387017d0c37a12b74f28b96028cbe0517e32e
|
4
|
+
data.tar.gz: f4adbd59e1b9b9a6578b56af633f3398562d5692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20eebb79bc3f800b937ff246676e67ca1ca6248bb3a47d27017cbf7b1dea39d2768c815d15d7c1ba236b902f12063e8ba15400d70af696edbbf22ebe34e8804d
|
7
|
+
data.tar.gz: 3b17da6034095a4e9b4d7cd5127e401be16ed2392605108e5c85673f5fc9665e97f24ff57991e4cbf12f1fc33400e9e08d2687e46fd2eb0c61b8cbc9242357dc
|
data/.travis.yml
ADDED
data/lib/helpstation.rb
CHANGED
@@ -7,7 +7,9 @@ require_relative 'helpstation/action'
|
|
7
7
|
require_relative 'helpstation/observer'
|
8
8
|
require_relative 'helpstation/renderer'
|
9
9
|
require_relative 'helpstation/legacy_process'
|
10
|
+
|
10
11
|
require_relative 'helpstation/fetchers'
|
12
|
+
require_relative 'helpstation/processors'
|
11
13
|
|
12
14
|
module Helpstation
|
13
15
|
def self.build_substation(env)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Helpstation
|
2
|
+
module Processors
|
3
|
+
# Helps to run processors in parallel
|
4
|
+
#
|
5
|
+
# All output from the processors are merged and then returned. This means
|
6
|
+
# that if two fetchers return results with the same key then one will
|
7
|
+
# overwrite the other.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# process ParallelProcessor[
|
11
|
+
# OperatorFetcher,
|
12
|
+
# VisitorFetcher
|
13
|
+
# ], NOT_FOUND_ERROR
|
14
|
+
#
|
15
|
+
class ParallelProcessor < Processor
|
16
|
+
def self.[](*processors)
|
17
|
+
new(processors)
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(processors)
|
21
|
+
@processors = processors
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(request)
|
25
|
+
results = process_parallel(request)
|
26
|
+
|
27
|
+
if first_failure = results.detect {|result| !result.success?}
|
28
|
+
first_failure
|
29
|
+
else
|
30
|
+
request.success(results.reduce(request.input, &method(:compose)))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def process_parallel(request)
|
37
|
+
@processors.map do |processor|
|
38
|
+
Thread.new { processor.call(request) }
|
39
|
+
end.map(&:join).map(&:value)
|
40
|
+
end
|
41
|
+
|
42
|
+
def compose(input, result)
|
43
|
+
input.merge(result.output)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/helpstation/version.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Helpstation::Evaluator do
|
4
|
+
subject { target_class.call(request) }
|
5
|
+
|
6
|
+
let(:request) { Substation::Request.new(:name, {}, {}) }
|
7
|
+
|
8
|
+
describe '#error' do
|
9
|
+
let(:target_class) do
|
10
|
+
Class.new(described_class) do
|
11
|
+
def call
|
12
|
+
error('ERROR', message: 'a message')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns an error response' do
|
18
|
+
should be_a(Substation::Response::Failure)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns status' do
|
22
|
+
expect(subject.output).to eq(
|
23
|
+
success: false, error: 'ERROR', message: 'a message'
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
File without changes
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Helpstation::Processors::ParallelProcessor do
|
4
|
+
subject { processor.call(request) }
|
5
|
+
|
6
|
+
let(:processor) { described_class[processor1, processor2] }
|
7
|
+
|
8
|
+
let(:processor1) do
|
9
|
+
Proc.new do |request|
|
10
|
+
sleep 0.1
|
11
|
+
request.success(request.input.merge(processor1: 'obj'))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:request) { Substation::Request.new(:name, {}, input) }
|
16
|
+
let(:input) { {initial: 'obj'} }
|
17
|
+
|
18
|
+
context 'when successful' do
|
19
|
+
let(:processor2) do
|
20
|
+
Proc.new do |request|
|
21
|
+
sleep 0.1
|
22
|
+
request.success(request.input.merge(processor2: 'obj'))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'runs in parallel' do
|
27
|
+
expect {
|
28
|
+
subject
|
29
|
+
}.to change(Time, :now).by_at_most(0.12)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'merges the results' do
|
33
|
+
should be_a(Substation::Response::Success)
|
34
|
+
expect(subject.output).to eq(
|
35
|
+
initial: 'obj',
|
36
|
+
processor1: 'obj',
|
37
|
+
processor2: 'obj'
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when one processor fails' do
|
43
|
+
let(:processor2) do
|
44
|
+
Proc.new do |request|
|
45
|
+
sleep 0.1
|
46
|
+
request.error(no: 'way')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns the error response' do
|
51
|
+
should be_a(Substation::Response::Failure)
|
52
|
+
expect(subject.output).to eq(no: 'way')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when one process has an exception' do
|
57
|
+
let(:processor2) do
|
58
|
+
Proc.new do |request|
|
59
|
+
sleep 0.1
|
60
|
+
this_throws_an_exception
|
61
|
+
request.success(processor2: 'obj')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'throws the exception' do
|
66
|
+
expect {
|
67
|
+
subject
|
68
|
+
}.to raise_error(NameError)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helpstation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Indrek Juhkam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: substation
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- ".rspec"
|
42
42
|
- ".ruby-gemset"
|
43
43
|
- ".ruby-version"
|
44
|
+
- ".travis.yml"
|
44
45
|
- Gemfile
|
45
46
|
- LICENSE.txt
|
46
47
|
- README.md
|
@@ -53,9 +54,12 @@ files:
|
|
53
54
|
- lib/helpstation/legacy_process.rb
|
54
55
|
- lib/helpstation/observer.rb
|
55
56
|
- lib/helpstation/processor.rb
|
57
|
+
- lib/helpstation/processors.rb
|
56
58
|
- lib/helpstation/renderer.rb
|
57
59
|
- lib/helpstation/version.rb
|
58
|
-
- spec/helpstation/
|
60
|
+
- spec/helpstation/evaluator_spec.rb
|
61
|
+
- spec/helpstation/fetchers/by_key_fetcher_spec.rb
|
62
|
+
- spec/helpstation/processors/parallel_processor_spec.rb
|
59
63
|
- spec/spec_helper.rb
|
60
64
|
homepage: ''
|
61
65
|
licenses:
|
@@ -82,5 +86,7 @@ signing_key:
|
|
82
86
|
specification_version: 4
|
83
87
|
summary: ''
|
84
88
|
test_files:
|
85
|
-
- spec/helpstation/
|
89
|
+
- spec/helpstation/evaluator_spec.rb
|
90
|
+
- spec/helpstation/fetchers/by_key_fetcher_spec.rb
|
91
|
+
- spec/helpstation/processors/parallel_processor_spec.rb
|
86
92
|
- spec/spec_helper.rb
|