cyclone_lariat 0.3.3 → 0.3.4
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de7e05c5fba57a9db6c827549404f12b1f88be0336b00d2d5dfb4dc77132b328
|
4
|
+
data.tar.gz: 54d81b79a812fdf91513cdee886933d32055fd405c55bb032aae4dec81ac1ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d8ce1ebcd03c53309165592b7e4e0cbe342a3033694afdc639e033fb76a88dd1f340ee2204c5602f02399a5e9e56f47a7483dba867d9aafcd9947b3958933c1
|
7
|
+
data.tar.gz: 8c8668274a9435e56804739e6625703b733810e46401aca602c04f51763274dafa9456f625fc315ae7b322c62d4a426a582a62db8b6061716ad46aced0ab5ef0
|
@@ -56,7 +56,6 @@ module CycloneLariat
|
|
56
56
|
publisher == other.publisher &&
|
57
57
|
type == other.type &&
|
58
58
|
client_error&.message == other.client_error&.message &&
|
59
|
-
client_error&.details == other.client_error&.details &&
|
60
59
|
version == other.version &&
|
61
60
|
sent_at.to_i == other.sent_at.to_i &&
|
62
61
|
received_at.to_i == other.received_at.to_i &&
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CycloneLariat
|
4
|
+
class MessagesMapper
|
5
|
+
class << self
|
6
|
+
def from_row(row)
|
7
|
+
return if row.nil?
|
8
|
+
|
9
|
+
row[:data] = hash_from_json_column(row[:data])
|
10
|
+
row[:client_error_details] = hash_from_json_column(row[:client_error_details]) if row[:client_error_details]
|
11
|
+
row
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_row(input)
|
15
|
+
row = {
|
16
|
+
uuid: input.uuid,
|
17
|
+
kind: input.kind,
|
18
|
+
type: input.type,
|
19
|
+
publisher: input.publisher,
|
20
|
+
data: JSON.generate(input.data),
|
21
|
+
client_error_message: input.client_error&.message,
|
22
|
+
client_error_details: JSON.generate(input.client_error&.details),
|
23
|
+
version: input.version,
|
24
|
+
sent_at: input.sent_at
|
25
|
+
}
|
26
|
+
row
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def hash_from_json_column(data)
|
32
|
+
return JSON.parse(data) if data.is_a?(String)
|
33
|
+
|
34
|
+
if pg_json_extension_enabled?
|
35
|
+
return data.to_h if data.is_a?(Sequel::Postgres::JSONHash)
|
36
|
+
return JSON.parse(data.to_s) if data.is_a?(Sequel::Postgres::JSONString)
|
37
|
+
end
|
38
|
+
|
39
|
+
raise ArgumentError, "Unknown type of `#{data}`"
|
40
|
+
end
|
41
|
+
|
42
|
+
def pg_json_extension_enabled?
|
43
|
+
Object.const_defined?('Sequel::Postgres::JSONHash')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'event'
|
4
|
+
require_relative 'messages_mapper'
|
4
5
|
|
5
6
|
module CycloneLariat
|
6
7
|
class MessagesRepo
|
@@ -11,17 +12,7 @@ module CycloneLariat
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def create(msg)
|
14
|
-
dataset.insert(
|
15
|
-
uuid: msg.uuid,
|
16
|
-
kind: msg.kind,
|
17
|
-
type: msg.type,
|
18
|
-
publisher: msg.publisher,
|
19
|
-
data: JSON.generate(msg.data),
|
20
|
-
client_error_message: msg.client_error&.message,
|
21
|
-
client_error_details: JSON.generate(msg.client_error&.details),
|
22
|
-
version: msg.version,
|
23
|
-
sent_at: msg.sent_at
|
24
|
-
)
|
15
|
+
dataset.insert MessagesMapper.to_row(msg)
|
25
16
|
end
|
26
17
|
|
27
18
|
def exists?(uuid:)
|
@@ -36,34 +27,20 @@ module CycloneLariat
|
|
36
27
|
end
|
37
28
|
|
38
29
|
def find(uuid:)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
raw[:data] = JSON.parse(raw[:data], symbolize_names: true)
|
43
|
-
if raw[:client_error_details]
|
44
|
-
raw[:client_error_details] = JSON.parse(raw[:client_error_details], symbolize_names: true)
|
45
|
-
end
|
46
|
-
build raw
|
30
|
+
row = dataset.where(uuid: uuid).first
|
31
|
+
build MessagesMapper.from_row(row)
|
47
32
|
end
|
48
33
|
|
49
34
|
def each_unprocessed
|
50
|
-
dataset.where(processed_at: nil).each do |
|
51
|
-
|
52
|
-
if raw[:client_error_details]
|
53
|
-
raw[:client_error_details] = JSON.parse(raw[:client_error_details], symbolize_names: true)
|
54
|
-
end
|
55
|
-
msg = build raw
|
35
|
+
dataset.where(processed_at: nil).each do |row|
|
36
|
+
msg = build MessagesMapper.from_row(row)
|
56
37
|
yield(msg)
|
57
38
|
end
|
58
39
|
end
|
59
40
|
|
60
41
|
def each_with_client_errors
|
61
|
-
dataset.where { (processed_at !~ nil) & (client_error_message !~ nil) }.each do |
|
62
|
-
|
63
|
-
if raw[:client_error_details]
|
64
|
-
raw[:client_error_details] = JSON.parse(raw[:client_error_details], symbolize_names: true)
|
65
|
-
end
|
66
|
-
msg = build raw
|
42
|
+
dataset.where { (processed_at !~ nil) & (client_error_message !~ nil) }.each do |row|
|
43
|
+
msg = build MessagesMapper.from_row(row)
|
67
44
|
yield(msg)
|
68
45
|
end
|
69
46
|
end
|
data/lib/cyclone_lariat.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative 'cyclone_lariat/sns_client'
|
4
4
|
require_relative 'cyclone_lariat/errors'
|
5
5
|
require_relative 'cyclone_lariat/event'
|
6
|
+
require_relative 'cyclone_lariat/messages_mapper'
|
6
7
|
require_relative 'cyclone_lariat/messages_repo'
|
7
8
|
require_relative 'cyclone_lariat/middleware'
|
8
9
|
require_relative 'cyclone_lariat/version'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyclone_lariat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kudrin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk-sns
|
@@ -279,6 +279,7 @@ files:
|
|
279
279
|
- lib/cyclone_lariat/command.rb
|
280
280
|
- lib/cyclone_lariat/errors.rb
|
281
281
|
- lib/cyclone_lariat/event.rb
|
282
|
+
- lib/cyclone_lariat/messages_mapper.rb
|
282
283
|
- lib/cyclone_lariat/messages_repo.rb
|
283
284
|
- lib/cyclone_lariat/middleware.rb
|
284
285
|
- lib/cyclone_lariat/sns_client.rb
|