alephant-sequencer 0.0.8 → 0.1.0
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/lib/alephant/sequencer/sequencer.rb +11 -8
- data/lib/alephant/sequencer/version.rb +1 -1
- data/spec/sequencer_spec.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3daf0b16c8239ed84c8714bdfd2ab292c65dcf14
|
4
|
+
data.tar.gz: 7fd66428f588bcc53a8806994bb768ef8720e16d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a35be4e9cd3f355923a65b8e59880ae9480826ab0062fc8d67b00bd1e7109b478006dfeee0634aeb6f45e2b450ad0a05988d79117859c919ffbfff65024f669
|
7
|
+
data.tar.gz: 76c2983a853d1e2146a50bc52f1a9767099539aafc9a29718a9639be0a59a6d47f76a2f48c80b533434769a9870a9ab3477d3996b304856e9cb47cefbf6749ca
|
@@ -5,16 +5,17 @@ require 'alephant/logger'
|
|
5
5
|
module Alephant
|
6
6
|
module Sequencer
|
7
7
|
class Sequencer
|
8
|
-
include
|
9
|
-
attr_reader :ident, :jsonpath
|
8
|
+
include Logger
|
9
|
+
attr_reader :ident, :jsonpath, :keep_all
|
10
10
|
|
11
|
-
def initialize(sequence_table, id, sequence_path)
|
11
|
+
def initialize(sequence_table, id, sequence_path, keep_all = true)
|
12
12
|
@sequence_table = sequence_table
|
13
13
|
@sequence_table.create
|
14
14
|
|
15
|
-
@
|
15
|
+
@keep_all = keep_all
|
16
|
+
@exists = exists?
|
16
17
|
@jsonpath = sequence_path
|
17
|
-
@ident
|
18
|
+
@ident = id
|
18
19
|
end
|
19
20
|
|
20
21
|
def sequential?(msg)
|
@@ -26,10 +27,12 @@ module Alephant
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def sequence(msg, &block)
|
29
|
-
block.call(msg)
|
30
|
-
|
31
30
|
last_seen_id = get_last_seen
|
32
|
-
|
31
|
+
sequential = ((last_seen_id || 0) < Sequencer.sequence_id_from(msg, jsonpath))
|
32
|
+
|
33
|
+
block.call(msg) if (sequential || keep_all)
|
34
|
+
|
35
|
+
if sequential
|
33
36
|
set_last_seen(msg, last_seen_id)
|
34
37
|
else
|
35
38
|
logger.info("Sequencer#sequence nonsequential message for #{ident}")
|
data/spec/sequencer_spec.rb
CHANGED
@@ -54,6 +54,15 @@ describe Alephant::Sequencer do
|
|
54
54
|
m
|
55
55
|
end
|
56
56
|
|
57
|
+
let(:an_uncalled_proc) do
|
58
|
+
a_block = double()
|
59
|
+
a_block.should_not_receive(:called).with(message)
|
60
|
+
|
61
|
+
Proc.new do |msg|
|
62
|
+
a_block.called(msg)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
57
66
|
let(:a_proc) do
|
58
67
|
a_block = double()
|
59
68
|
a_block.should_receive(:called).with(message)
|
@@ -138,6 +147,19 @@ describe Alephant::Sequencer do
|
|
138
147
|
subject = Alephant::Sequencer::Sequencer.new(sequence_table, ident, jsonpath)
|
139
148
|
subject.sequence(message, &a_proc)
|
140
149
|
end
|
150
|
+
|
151
|
+
context "keep_all is false" do
|
152
|
+
let(:keep_all) { false }
|
153
|
+
it "should not call the passed block with msg" do
|
154
|
+
subject = Alephant::Sequencer::Sequencer.new(
|
155
|
+
sequence_table,
|
156
|
+
ident,
|
157
|
+
jsonpath,
|
158
|
+
keep_all
|
159
|
+
)
|
160
|
+
subject.sequence(message, &an_uncalled_proc)
|
161
|
+
end
|
162
|
+
end
|
141
163
|
end
|
142
164
|
|
143
165
|
context "last_seen_id < sequence_id_from(msg)" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-sequencer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Kenny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|