alephant-sequencer 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86b1297e01bdbd2d4c4f81a602b34e895b5ada82
|
4
|
+
data.tar.gz: e492fe5944c17e92b1afbc7ff0f8270558abe51d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83507711dee28f0b1a8d0abb4a2b5f06927caf541c641d18d4d566d0087320cf10f354e82672de1831c238735a396fe88b8edeae66843a8554de73278877cf6a
|
7
|
+
data.tar.gz: 88468c9d3df88230e5db48fe3f722e89c0bf18a92756555082f4f8179b6181d3a6ec110f4b9063f2051e8eae3ed32922f05d0b9f9d36f53f108896cd9a65c154
|
@@ -8,8 +8,7 @@ require "alephant/support/dynamodb/table"
|
|
8
8
|
module Alephant
|
9
9
|
module Sequencer
|
10
10
|
class SequenceTable < ::Alephant::Support::DynamoDB::Table
|
11
|
-
include
|
12
|
-
|
11
|
+
include Logger
|
13
12
|
attr_reader :table_name, :client
|
14
13
|
|
15
14
|
def initialize(table_name)
|
@@ -36,7 +35,7 @@ module Alephant
|
|
36
35
|
data.length > 0 ? data[:item]["value"][:n].to_i : 0
|
37
36
|
end
|
38
37
|
|
39
|
-
def
|
38
|
+
def update_sequence_id(ident, value, last_seen_check = nil)
|
40
39
|
begin
|
41
40
|
|
42
41
|
current_sequence = last_seen_check.nil? ? sequence_for(ident) : last_seen_check
|
@@ -67,9 +66,9 @@ module Alephant
|
|
67
66
|
})
|
68
67
|
end
|
69
68
|
|
70
|
-
logger.info("SequenceTable#
|
71
|
-
rescue AWS::DynamoDB::Errors::ConditionalCheckFailedException
|
72
|
-
logger.warn("SequenceTable#
|
69
|
+
logger.info("SequenceTable#update_sequence_id: with new value #{value} for #{ident} success!")
|
70
|
+
rescue AWS::DynamoDB::Errors::ConditionalCheckFailedException
|
71
|
+
logger.warn("SequenceTable#update_sequence_id: (Value to put: #{value}, existing: #{current_sequence}) #{ident} outdated!")
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'jsonpath'
|
2
|
-
|
3
2
|
require 'alephant/logger'
|
4
3
|
|
5
4
|
module Alephant
|
@@ -15,6 +14,7 @@ module Alephant
|
|
15
14
|
@exists = exists?
|
16
15
|
@jsonpath = sequence_path
|
17
16
|
@ident = id
|
17
|
+
logger.info("Sequencer#initialize: table: #{sequence_table}, jsonpath: #{sequence_path}, id: #{id}")
|
18
18
|
end
|
19
19
|
|
20
20
|
def sequential?(msg)
|
@@ -29,12 +29,12 @@ module Alephant
|
|
29
29
|
last_seen_id = get_last_seen
|
30
30
|
sequential = ((last_seen_id || 0) < Sequencer.sequence_id_from(msg, jsonpath))
|
31
31
|
|
32
|
-
block.call
|
32
|
+
block.call if (sequential || keep_all)
|
33
33
|
|
34
34
|
if sequential
|
35
35
|
set_last_seen(msg, last_seen_id)
|
36
36
|
else
|
37
|
-
logger.info("Sequencer#sequence nonsequential message for #{ident}")
|
37
|
+
logger.info("Sequencer#sequence nonsequential message for #{ident} (last_seen_id: #{last_seen_id})")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -51,7 +51,7 @@ module Alephant
|
|
51
51
|
def set_last_seen(msg, last_seen_check = nil)
|
52
52
|
seen_id = Sequencer.sequence_id_from(msg, jsonpath)
|
53
53
|
|
54
|
-
@sequence_table.
|
54
|
+
@sequence_table.update_sequence_id(
|
55
55
|
ident, seen_id,
|
56
56
|
(exists? ? last_seen_check : nil)
|
57
57
|
)
|
data/spec/sequencer_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe Alephant::Sequencer do
|
|
25
25
|
table.stub(:create)
|
26
26
|
table.stub(:sequence_exists)
|
27
27
|
table.stub(:sequence_for)
|
28
|
-
table.stub(:
|
28
|
+
table.stub(:update_sequence_id)
|
29
29
|
table.stub(:truncate!)
|
30
30
|
table
|
31
31
|
end
|
@@ -58,10 +58,10 @@ describe Alephant::Sequencer do
|
|
58
58
|
|
59
59
|
let(:a_proc) do
|
60
60
|
a_block = double()
|
61
|
-
a_block.should_receive(:called)
|
61
|
+
a_block.should_receive(:called)
|
62
62
|
|
63
|
-
Proc.new do
|
64
|
-
a_block.called
|
63
|
+
Proc.new do
|
64
|
+
a_block.called
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -69,7 +69,7 @@ describe Alephant::Sequencer do
|
|
69
69
|
let(:stubbed_seen_high) { 3 }
|
70
70
|
let(:stubbed_seen_low) { 1 }
|
71
71
|
|
72
|
-
it "should call the passed block
|
72
|
+
it "should call the passed block" do
|
73
73
|
subject = Alephant::Sequencer::Sequencer.new(sequence_table, ident, jsonpath)
|
74
74
|
subject.validate(message, &a_proc)
|
75
75
|
end
|
@@ -203,12 +203,12 @@ describe Alephant::Sequencer do
|
|
203
203
|
.and_return(last_seen)
|
204
204
|
end
|
205
205
|
|
206
|
-
it "calls
|
206
|
+
it "calls update_sequence_id(ident, last_seen)" do
|
207
207
|
table = double()
|
208
208
|
table.stub(:sequence_exists)
|
209
209
|
table.stub(:create)
|
210
210
|
table.stub(:sequence_for)
|
211
|
-
table.should_receive(:
|
211
|
+
table.should_receive(:update_sequence_id)
|
212
212
|
.with(ident, last_seen, nil)
|
213
213
|
|
214
214
|
Alephant::Sequencer::Sequencer
|