alephant-sequencer 0.1.1 → 0.2.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: 63945d43d55c22f78538848da3260f0476eed6a7
4
- data.tar.gz: 3f32fc5e8bdf2598cec0d55de607a158fecc7eef
3
+ metadata.gz: 0d63fd87b204cb85599cefff8afdb383fb73d44f
4
+ data.tar.gz: 941c6807d5ae508a7877c3dc8bdd5271426294d3
5
5
  SHA512:
6
- metadata.gz: 5db714dd5a3758bd4a81b8dfdf857aa6fedbadd4ea83db9b5d86b505168d7de52f9260855cac7678c7795b41af592d08e7212760d46ca54fbf7ab16b45f24bc0
7
- data.tar.gz: ec1843f63176369541ce0ed129da354f90736262e892a91c903a5c90cc0dd6d54e005beb003e0ebedbbc51d0db6737dd1096452a6c31c07e2d34ab5d7ebb4a30
6
+ metadata.gz: 201995cd61b5593347f13f124a308c639a970a1c8eb0078d2bd6a0377ea045c75220f44ae9570342f8ec027d00fcb5f70e1b026672f68d94f9179b758ca9fa33
7
+ data.tar.gz: 35d0c7bee1dc6dc99beaef458e7ca5473fd90ce18b0c08bb97135ff0e2eba46e1e415fc7e3f13e16ff0192c2ee94173affe2063c94453bc9e821c42dfb58ba8e
@@ -10,119 +10,88 @@ module Alephant
10
10
  class SequenceTable < ::Alephant::Support::DynamoDB::Table
11
11
  include ::Alephant::Logger
12
12
 
13
- attr_reader :table_name
13
+ attr_reader :table_name, :client
14
14
 
15
- SCHEMA = {
16
- :hash_key => {
17
- :key => :string,
18
- :value => :string
19
- }
20
- }
21
-
22
- def initialize(table_name, config = DEFAULT_CONFIG)
23
- @mutex = Mutex.new
24
- @dynamo_db = AWS::DynamoDB.new
15
+ def initialize(table_name)
16
+ @mutex = Mutex.new
17
+ @client = AWS::DynamoDB::Client::V20120810.new
25
18
  @table_name = table_name
26
- @config = config
27
19
  end
28
20
 
29
- def create
30
- @mutex.synchronize do
31
- ensure_table_exists
32
- ensure_table_active
21
+ def sequence_exists(ident)
22
+ if ident.nil?
23
+ return false
33
24
  end
34
- end
35
25
 
36
- def table
37
- @table ||= @dynamo_db.tables[@table_name]
38
- end
39
-
40
- def sequence_exists(ident)
41
- !(table.items.where(:key => ident) == 0)
26
+ !(client.get_item(
27
+ item_payload(ident)
28
+ ).length == 0)
42
29
  end
43
30
 
44
31
  def sequence_for(ident)
45
- rows = batch_get_value_for(ident)
46
- rows.count >= 1 ? rows.first["value"].to_i : nil
32
+ data = client.get_item(
33
+ item_payload(ident)
34
+ )
35
+
36
+ data.length > 0 ? data[:item]["value"][:n].to_i : 0
47
37
  end
48
38
 
49
39
  def set_sequence_for(ident, value, last_seen_check = nil)
50
40
  begin
41
+
42
+ current_sequence = last_seen_check.nil? ? sequence_for(ident) : last_seen_check
51
43
  @mutex.synchronize do
52
- table.items.put(
53
- {:key => ident, :value => value },
54
- put_condition(last_seen_check)
55
- )
44
+
45
+ client.put_item({
46
+ :table_name => table_name,
47
+ :item => {
48
+ 'key' => {
49
+ 'S' => ident
50
+ },
51
+ 'value' => {
52
+ 'N' => value.to_s
53
+ }
54
+ },
55
+ :expected => {
56
+ 'key' => {
57
+ :comparison_operator => 'NULL'
58
+ },
59
+ 'value' => {
60
+ :comparison_operator => 'GE',
61
+ :attribute_value_list => [
62
+ { 'N' => current_sequence.to_s }
63
+ ]
64
+ }
65
+ },
66
+ :conditional_operator => 'OR'
67
+ })
56
68
  end
57
69
 
58
70
  logger.info("SequenceTable#set_sequence_for: #{value} for #{ident} success!")
59
71
  rescue AWS::DynamoDB::Errors::ConditionalCheckFailedException => e
60
- logger.warn("SequenceTable#set_sequence_for: #{ident} #{e.message}")
61
- last_seen_check = sequence_for(ident)
62
-
63
- unless last_seen_check >= value
64
- logger.info("SequenceTable#set_sequence_for: #{ident} trying again!")
65
- set_sequence_for(ident, value, last_seen_check)
66
- else
67
- logger.warn("SequenceTable#set_sequence_for: #{ident} outdated!")
68
- end
72
+ logger.warn("SequenceTable#set_sequence_for: (Value to put: #{value}, existing: #{current_sequence}) #{ident} outdated!")
69
73
  end
70
74
  end
71
75
 
72
76
  def delete_item!(ident)
73
- table.items[ident].delete
77
+ client.delete_item(
78
+ item_payload(ident)
79
+ )
74
80
  end
75
81
 
76
82
  private
77
83
 
78
- def put_condition(last_seen_check)
79
- last_seen_check.nil? ? unless_exists(:key) : if_value(last_seen_check)
80
- end
81
-
82
- def batch_get_value_for(ident)
83
- table.batch_get(["value"],[ident],batch_get_opts)
84
- end
85
-
86
- def unless_exists(key)
87
- { :unless_exists => key }
88
- end
89
-
90
- def if_value(value)
91
- { :if => { :value => value.to_i } }
92
- end
93
-
94
- def batch_get_opts
95
- { :consistent_read => true }
96
- end
97
-
98
- def ensure_table_exists
99
- create_dynamodb_table unless table.exists?
100
- end
101
-
102
- def ensure_table_active
103
- sleep_until_table_active unless table_active?
104
- end
105
-
106
- def create_dynamodb_table
107
- @table = @dynamo_db.tables.create(
108
- @table_name,
109
- @config[:read_units],
110
- @config[:write_units],
111
- SCHEMA
112
- )
113
- end
114
-
115
- def table_active?
116
- table.status == :active
84
+ def item_payload(ident)
85
+ {
86
+ :table_name => table_name,
87
+ :key => {
88
+ 'key' => {
89
+ 'S' => ident.to_s
90
+ }
91
+ }
92
+ }
117
93
  end
118
94
 
119
- def sleep_until_table_active
120
- begin
121
- Timeout::timeout(TIMEOUT) do
122
- sleep 1 until table_active?
123
- end
124
- end
125
- end
126
95
  end
127
96
  end
128
97
  end
@@ -10,7 +10,6 @@ module Alephant
10
10
 
11
11
  def initialize(sequence_table, id, sequence_path, keep_all = true)
12
12
  @sequence_table = sequence_table
13
- @sequence_table.create
14
13
 
15
14
  @keep_all = keep_all
16
15
  @exists = exists?
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Sequencer
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
Binary file
@@ -38,13 +38,6 @@ describe Alephant::Sequencer do
38
38
  expect(subject.ident).to eq(ident)
39
39
  end
40
40
 
41
- it "calls create on sequence_table" do
42
- table = double()
43
- table.stub(:sequence_exists)
44
- table.should_receive(:create)
45
-
46
- Alephant::Sequencer::Sequencer.new(table, ident, jsonpath)
47
- end
48
41
  end
49
42
 
50
43
  describe "#sequence(msg, &block)" do
metadata CHANGED
@@ -1,198 +1,198 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-sequencer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Kenny
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-14 00:00:00.000000000 Z
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
- requirement: !ruby/object:Gem::Requirement
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
21
23
  requirements:
22
24
  - - ~>
23
25
  - !ruby/object:Gem::Version
24
26
  version: '1.5'
25
- prerelease: false
26
- type: :development
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
29
  requirement: !ruby/object:Gem::Requirement
35
30
  requirements:
36
31
  - - '>='
37
32
  - !ruby/object:Gem::Version
38
33
  version: '0'
39
- prerelease: false
40
34
  type: :development
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
35
+ prerelease: false
43
36
  version_requirements: !ruby/object:Gem::Requirement
44
37
  requirements:
45
38
  - - '>='
46
39
  - !ruby/object:Gem::Version
47
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
44
  requirements:
50
45
  - - '>='
51
46
  - !ruby/object:Gem::Version
52
47
  version: '0'
53
- prerelease: false
54
48
  type: :development
55
- - !ruby/object:Gem::Dependency
56
- name: rspec-nc
49
+ prerelease: false
57
50
  version_requirements: !ruby/object:Gem::Requirement
58
51
  requirements:
59
52
  - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-nc
62
57
  requirement: !ruby/object:Gem::Requirement
63
58
  requirements:
64
59
  - - '>='
65
60
  - !ruby/object:Gem::Version
66
61
  version: '0'
67
- prerelease: false
68
62
  type: :development
69
- - !ruby/object:Gem::Dependency
70
- name: guard
63
+ prerelease: false
71
64
  version_requirements: !ruby/object:Gem::Requirement
72
65
  requirements:
73
66
  - - '>='
74
67
  - !ruby/object:Gem::Version
75
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard
76
71
  requirement: !ruby/object:Gem::Requirement
77
72
  requirements:
78
73
  - - '>='
79
74
  - !ruby/object:Gem::Version
80
75
  version: '0'
81
- prerelease: false
82
76
  type: :development
83
- - !ruby/object:Gem::Dependency
84
- name: guard-rspec
77
+ prerelease: false
85
78
  version_requirements: !ruby/object:Gem::Requirement
86
79
  requirements:
87
80
  - - '>='
88
81
  - !ruby/object:Gem::Version
89
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
90
85
  requirement: !ruby/object:Gem::Requirement
91
86
  requirements:
92
87
  - - '>='
93
88
  - !ruby/object:Gem::Version
94
89
  version: '0'
95
- prerelease: false
96
90
  type: :development
97
- - !ruby/object:Gem::Dependency
98
- name: pry
91
+ prerelease: false
99
92
  version_requirements: !ruby/object:Gem::Requirement
100
93
  requirements:
101
94
  - - '>='
102
95
  - !ruby/object:Gem::Version
103
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
104
99
  requirement: !ruby/object:Gem::Requirement
105
100
  requirements:
106
101
  - - '>='
107
102
  - !ruby/object:Gem::Version
108
103
  version: '0'
109
- prerelease: false
110
104
  type: :development
111
- - !ruby/object:Gem::Dependency
112
- name: pry-remote
105
+ prerelease: false
113
106
  version_requirements: !ruby/object:Gem::Requirement
114
107
  requirements:
115
108
  - - '>='
116
109
  - !ruby/object:Gem::Version
117
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-remote
118
113
  requirement: !ruby/object:Gem::Requirement
119
114
  requirements:
120
115
  - - '>='
121
116
  - !ruby/object:Gem::Version
122
117
  version: '0'
123
- prerelease: false
124
118
  type: :development
125
- - !ruby/object:Gem::Dependency
126
- name: pry-nav
119
+ prerelease: false
127
120
  version_requirements: !ruby/object:Gem::Requirement
128
121
  requirements:
129
122
  - - '>='
130
123
  - !ruby/object:Gem::Version
131
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-nav
132
127
  requirement: !ruby/object:Gem::Requirement
133
128
  requirements:
134
129
  - - '>='
135
130
  - !ruby/object:Gem::Version
136
131
  version: '0'
137
- prerelease: false
138
132
  type: :development
139
- - !ruby/object:Gem::Dependency
140
- name: aws-sdk
133
+ prerelease: false
141
134
  version_requirements: !ruby/object:Gem::Requirement
142
135
  requirements:
143
- - - ~>
136
+ - - '>='
144
137
  - !ruby/object:Gem::Version
145
- version: '1.0'
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: aws-sdk
146
141
  requirement: !ruby/object:Gem::Requirement
147
142
  requirements:
148
143
  - - ~>
149
144
  - !ruby/object:Gem::Version
150
145
  version: '1.0'
151
- prerelease: false
152
146
  type: :runtime
153
- - !ruby/object:Gem::Dependency
154
- name: alephant-logger
147
+ prerelease: false
155
148
  version_requirements: !ruby/object:Gem::Requirement
156
149
  requirements:
157
- - - '>='
150
+ - - ~>
158
151
  - !ruby/object:Gem::Version
159
- version: '0'
152
+ version: '1.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: alephant-logger
160
155
  requirement: !ruby/object:Gem::Requirement
161
156
  requirements:
162
157
  - - '>='
163
158
  - !ruby/object:Gem::Version
164
159
  version: '0'
165
- prerelease: false
166
160
  type: :runtime
167
- - !ruby/object:Gem::Dependency
168
- name: alephant-support
161
+ prerelease: false
169
162
  version_requirements: !ruby/object:Gem::Requirement
170
163
  requirements:
171
164
  - - '>='
172
165
  - !ruby/object:Gem::Version
173
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: alephant-support
174
169
  requirement: !ruby/object:Gem::Requirement
175
170
  requirements:
176
171
  - - '>='
177
172
  - !ruby/object:Gem::Version
178
173
  version: '0'
179
- prerelease: false
180
174
  type: :runtime
181
- - !ruby/object:Gem::Dependency
182
- name: jsonpath
175
+ prerelease: false
183
176
  version_requirements: !ruby/object:Gem::Requirement
184
177
  requirements:
185
178
  - - '>='
186
179
  - !ruby/object:Gem::Version
187
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: jsonpath
188
183
  requirement: !ruby/object:Gem::Requirement
189
184
  requirements:
190
185
  - - '>='
191
186
  - !ruby/object:Gem::Version
192
187
  version: '0'
193
- prerelease: false
194
188
  type: :runtime
195
- description:
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description:
196
196
  email:
197
197
  - kenoir@gmail.com
198
198
  executables: []
@@ -211,13 +211,14 @@ files:
211
211
  - lib/alephant/sequencer/sequence_table.rb
212
212
  - lib/alephant/sequencer/sequencer.rb
213
213
  - lib/alephant/sequencer/version.rb
214
+ - spec/.sequencer_spec.rb.swp
214
215
  - spec/sequencer_spec.rb
215
216
  - spec/spec_helper.rb
216
217
  homepage: ''
217
218
  licenses:
218
219
  - MIT
219
220
  metadata: {}
220
- post_install_message:
221
+ post_install_message:
221
222
  rdoc_options: []
222
223
  require_paths:
223
224
  - lib
@@ -232,11 +233,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
233
  - !ruby/object:Gem::Version
233
234
  version: '0'
234
235
  requirements: []
235
- rubyforge_project:
236
- rubygems_version: 2.1.9
237
- signing_key:
236
+ rubyforge_project:
237
+ rubygems_version: 2.2.2
238
+ signing_key:
238
239
  specification_version: 4
239
240
  summary: Adds sequencing functionality to Alephant.
240
241
  test_files:
242
+ - spec/.sequencer_spec.rb.swp
241
243
  - spec/sequencer_spec.rb
242
244
  - spec/spec_helper.rb