quarantine 1.0.5 → 1.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fc1311c40c02cd62c89672cad8ef3504a0abe8cb0e9c6eb4a3ccdf4a7acc664
4
- data.tar.gz: a8afa4b5d8de5c26e5a03790d0d053c77044caf08fde8cdd4dde2165a33e48e2
3
+ metadata.gz: aaede44e051f9b183da284c82c86ae341ac4361bb8c36ba12f7cb11c4fc47350
4
+ data.tar.gz: dce85fa1bac7d33224b907e53ed570763b87cbd783ae983d88e7dc563b0b0db0
5
5
  SHA512:
6
- metadata.gz: 84bf594f24acca0a92cb49da883368de553a816ac3d0f4f58b3bf5c147db86019c858f1f1f9a11d38e9e2af5de859a07e29d6b46c239972c33ae23a008f12ad2
7
- data.tar.gz: 2e9f6d30eff342421f12a99bedf64888cdca6406b20496fa481309acb1df7eb1acc70e0ada1d8821780a23fc9296e1254727f343c0c1d716db1679117d4e2471
6
+ metadata.gz: dc724bcd18323c374bd1e8c5ae472db1579d9334e4d050c352058902981488a5659b542c26ba464e88d47bb102efb20ce9faa5990ba098225200cab11324792f
7
+ data.tar.gz: 63d3dbeb70b087ba783a925cd57d1cf76488fbaae6819b53509fafe3b6609e2fb0e126f3ae03e70f00ebfe358cd93e42e4341bd44790b4773e6cf7c3d1921655
@@ -1,3 +1,6 @@
1
+ ### 1.0.6
2
+ Update DynamoDB batch_write_item implementation to check for duplicates based on different keys before uploading
3
+
1
4
  ### 1.0.5
2
5
  Add aws_credentials argument during dynamodb initialization to override the AWS SDK credential chain
3
6
 
@@ -16,7 +16,7 @@ class Quarantine
16
16
 
17
17
  def scan(table_name)
18
18
  begin
19
- result = dynamodb.scan({ table_name: table_name })
19
+ result = dynamodb.scan(table_name: table_name)
20
20
  rescue Aws::DynamoDB::Errors::ServiceError
21
21
  raise Quarantine::DatabaseError
22
22
  end
@@ -24,17 +24,32 @@ class Quarantine
24
24
  result&.items
25
25
  end
26
26
 
27
- def batch_write_item(table_name, items, additional_attributes = {})
27
+ def batch_write_item(table_name, items, additional_attributes = {}, dedup_keys = %w[id full_description])
28
+ return if items.empty?
29
+
30
+ # item_a is a duplicate of item_b if all values for each dedup_key in both item_a and item_b match
31
+ is_a_duplicate = ->(item_a, item_b) { dedup_keys.all? { |key| item_a[key] == item_b[key] } }
32
+
33
+ scanned_items = scan(table_name)
34
+
35
+ deduped_items = items.reject do |item|
36
+ scanned_items.any? do |scanned_item|
37
+ is_a_duplicate.call(item.to_string_hash, scanned_item)
38
+ end
39
+ end
40
+
41
+ return if deduped_items.empty?
42
+
28
43
  dynamodb.batch_write_item(
29
- { request_items: {
30
- table_name => items.map do |item|
44
+ request_items: {
45
+ table_name => deduped_items.map do |item|
31
46
  {
32
47
  put_request: {
33
48
  item: { **item.to_hash, **additional_attributes }
34
49
  }
35
50
  }
36
51
  end
37
- } }
52
+ }
38
53
  )
39
54
  rescue Aws::DynamoDB::Errors::ServiceError
40
55
  raise Quarantine::DatabaseError
@@ -42,11 +57,9 @@ class Quarantine
42
57
 
43
58
  def delete_item(table_name, keys)
44
59
  dynamodb.delete_item(
45
- {
46
- table_name: table_name,
47
- key: {
48
- **keys
49
- }
60
+ table_name: table_name,
61
+ key: {
62
+ **keys
50
63
  }
51
64
  )
52
65
  rescue Aws::DynamoDB::Errors::ServiceError
@@ -20,5 +20,14 @@ class Quarantine
20
20
  build_number: build_number
21
21
  }
22
22
  end
23
+
24
+ def to_string_hash
25
+ {
26
+ 'id' => id,
27
+ 'full_description' => full_description,
28
+ 'location' => location,
29
+ 'build_number' => build_number
30
+ }
31
+ end
23
32
  end
24
33
  end
@@ -1,3 +1,3 @@
1
1
  class Quarantine
2
- VERSION = '1.0.5'.freeze
2
+ VERSION = '1.0.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quarantine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flexport Engineering, Eric Zhu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-30 00:00:00.000000000 Z
11
+ date: 2020-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
- rubygems_version: 3.0.4
94
+ rubygems_version: 3.0.2
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Quarantine flaky Ruby Rspec tests