cyclone_lariat 1.0.0.rc2 → 1.0.0.rc3
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/CHANGELOG.md +4 -0
- data/Gemfile.lock +5 -5
- data/lib/cyclone_lariat/messages/abstract.rb +138 -0
- data/lib/cyclone_lariat/messages/builder.rb +83 -0
- data/lib/cyclone_lariat/messages/common.rb +39 -0
- data/lib/cyclone_lariat/messages/v1/command.rb +3 -3
- data/lib/cyclone_lariat/messages/v1/event.rb +3 -3
- data/lib/cyclone_lariat/messages/v2/command.rb +27 -3
- data/lib/cyclone_lariat/messages/v2/event.rb +27 -3
- data/lib/cyclone_lariat/middleware.rb +2 -1
- data/lib/cyclone_lariat/repo/active_record/messages.rb +2 -5
- data/lib/cyclone_lariat/repo/sequel/messages.rb +2 -5
- data/lib/cyclone_lariat/version.rb +1 -1
- metadata +5 -4
- data/lib/cyclone_lariat/messages/v1/abstract.rb +0 -139
- data/lib/cyclone_lariat/messages/v2/abstract.rb +0 -149
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2611c13c5fb86d9aa353ae3df16d5c216fb02be
|
4
|
+
data.tar.gz: b90c6880d34961111dc73cb9f794561fa2a42630
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '092ed1050daccad64005c8c91d586057f011881ddc3564f60892f27951b67b5e4f038730143273dd724e7792310206aab0c77ab09500f13933573fb0b03590b9'
|
7
|
+
data.tar.gz: 8b2b9d21456541871afd95dfd0b20057bdcdea543dce49b5ad34a66eb026067ef3869ae785b3962334783e371b293d8f3daf0eec9b7766ce112cbb43235e6d12
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [1.0.0.rc3]
|
8
|
+
Added
|
9
|
+
- `CycloneLariat::Messages::Builder` for building messages
|
10
|
+
|
7
11
|
## [1.0.0.rc2]
|
8
12
|
Changed
|
9
13
|
- README.md file
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cyclone_lariat (1.0.0.
|
4
|
+
cyclone_lariat (1.0.0.rc3)
|
5
5
|
aws-sdk-sns
|
6
6
|
aws-sdk-sqs
|
7
7
|
dry-cli (~> 0.6)
|
@@ -28,16 +28,16 @@ GEM
|
|
28
28
|
arel (9.0.0)
|
29
29
|
ast (2.4.2)
|
30
30
|
aws-eventstream (1.2.0)
|
31
|
-
aws-partitions (1.
|
32
|
-
aws-sdk-core (3.
|
31
|
+
aws-partitions (1.703.0)
|
32
|
+
aws-sdk-core (3.170.0)
|
33
33
|
aws-eventstream (~> 1, >= 1.0.2)
|
34
34
|
aws-partitions (~> 1, >= 1.651.0)
|
35
35
|
aws-sigv4 (~> 1.5)
|
36
36
|
jmespath (~> 1, >= 1.6.1)
|
37
|
-
aws-sdk-sns (1.
|
37
|
+
aws-sdk-sns (1.59.0)
|
38
38
|
aws-sdk-core (~> 3, >= 3.165.0)
|
39
39
|
aws-sigv4 (~> 1.1)
|
40
|
-
aws-sdk-sqs (1.
|
40
|
+
aws-sdk-sqs (1.53.0)
|
41
41
|
aws-sdk-core (~> 3, >= 3.165.0)
|
42
42
|
aws-sigv4 (~> 1.1)
|
43
43
|
aws-sigv4 (1.5.2)
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'luna_park/entities/attributable'
|
4
|
+
require 'luna_park/extensions/validatable'
|
5
|
+
require 'cyclone_lariat/errors'
|
6
|
+
|
7
|
+
module CycloneLariat
|
8
|
+
module Messages
|
9
|
+
class Abstract < LunaPark::Entities::Attributable
|
10
|
+
include LunaPark::Extensions::Validatable
|
11
|
+
|
12
|
+
KIND = 'unknown'
|
13
|
+
|
14
|
+
attr :uuid, String, :new
|
15
|
+
attr :publisher, String, :new
|
16
|
+
attr :type, String, :new
|
17
|
+
|
18
|
+
attrs :client_error, :version, :data, :request_id, :sent_at,
|
19
|
+
:deduplication_id, :group_id, :processed_at, :received_at
|
20
|
+
|
21
|
+
# Make validation public
|
22
|
+
def validation
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def kind
|
27
|
+
KIND
|
28
|
+
end
|
29
|
+
|
30
|
+
def serialize
|
31
|
+
{
|
32
|
+
uuid: uuid,
|
33
|
+
publisher: publisher,
|
34
|
+
type: [kind, type].join('_'),
|
35
|
+
version: version,
|
36
|
+
data: data,
|
37
|
+
request_id: request_id,
|
38
|
+
sent_at: sent_at&.iso8601(3)
|
39
|
+
}.compact
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_json(*args)
|
43
|
+
serialize.to_json(*args)
|
44
|
+
end
|
45
|
+
|
46
|
+
def params
|
47
|
+
serialize
|
48
|
+
end
|
49
|
+
|
50
|
+
def data
|
51
|
+
@data ||= {}
|
52
|
+
end
|
53
|
+
|
54
|
+
def version=(value)
|
55
|
+
@version = Integer(value)
|
56
|
+
end
|
57
|
+
|
58
|
+
def sent_at=(value)
|
59
|
+
@sent_at = wrap_time(value)
|
60
|
+
end
|
61
|
+
|
62
|
+
def received_at=(value)
|
63
|
+
@received_at = wrap_time(value)
|
64
|
+
end
|
65
|
+
|
66
|
+
def processed_at=(value)
|
67
|
+
@processed_at = wrap_time(value)
|
68
|
+
end
|
69
|
+
|
70
|
+
def request_id=(value)
|
71
|
+
@request_id = wrap_string(value)
|
72
|
+
end
|
73
|
+
|
74
|
+
def group_id=(value)
|
75
|
+
@group_id = wrap_string(value)
|
76
|
+
end
|
77
|
+
|
78
|
+
def deduplication_id=(value)
|
79
|
+
@deduplication_id = wrap_string(value)
|
80
|
+
end
|
81
|
+
|
82
|
+
def processed?
|
83
|
+
!@processed_at.nil?
|
84
|
+
end
|
85
|
+
|
86
|
+
def client_error_message=(txt)
|
87
|
+
return unless txt
|
88
|
+
|
89
|
+
@client_error ||= Errors::ClientError.new
|
90
|
+
@client_error.message = txt
|
91
|
+
end
|
92
|
+
|
93
|
+
def client_error_details=(details)
|
94
|
+
return unless details
|
95
|
+
|
96
|
+
@client_error ||= Errors::ClientError.new
|
97
|
+
@client_error.details = details
|
98
|
+
end
|
99
|
+
|
100
|
+
def fifo?
|
101
|
+
!@group_id.nil?
|
102
|
+
end
|
103
|
+
|
104
|
+
def ==(other)
|
105
|
+
kind == other.kind &&
|
106
|
+
uuid == other.uuid &&
|
107
|
+
publisher == other.publisher &&
|
108
|
+
type == other.type &&
|
109
|
+
client_error&.message == other.client_error&.message &&
|
110
|
+
version == other.version &&
|
111
|
+
sent_at.to_i == other.sent_at.to_i &&
|
112
|
+
received_at.to_i == other.received_at.to_i &&
|
113
|
+
processed_at.to_i == other.processed_at.to_i
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def wrap_time(value)
|
119
|
+
case value
|
120
|
+
when String then Time.parse(value)
|
121
|
+
when Time then value
|
122
|
+
when NilClass then nil
|
123
|
+
else raise ArgumentError, "Unknown type `#{value.class}`"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def wrap_string(value)
|
128
|
+
case value
|
129
|
+
when String then String(value)
|
130
|
+
when Integer then String(value)
|
131
|
+
when NilClass then nil
|
132
|
+
when FalseClass then nil
|
133
|
+
else raise ArgumentError, "Unknown type `#{value.class}`"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cyclone_lariat/messages/v1/event'
|
4
|
+
require 'cyclone_lariat/messages/v1/command'
|
5
|
+
require 'cyclone_lariat/messages/v2/event'
|
6
|
+
require 'cyclone_lariat/messages/v2/command'
|
7
|
+
require 'cyclone_lariat/messages/common'
|
8
|
+
|
9
|
+
module CycloneLariat
|
10
|
+
module Messages
|
11
|
+
class Builder
|
12
|
+
attr_reader :raw_message
|
13
|
+
|
14
|
+
def initialize(raw_message:)
|
15
|
+
@raw_message = raw_message
|
16
|
+
@kind = kind
|
17
|
+
@raw_message[:type] = message_type
|
18
|
+
end
|
19
|
+
|
20
|
+
def call
|
21
|
+
case @kind
|
22
|
+
when 'event' then event_builder
|
23
|
+
when 'command' then command_builder
|
24
|
+
else Messages::Common.wrap(message_without_kind)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def event_builder
|
31
|
+
case message_version
|
32
|
+
when 1 then event_v1
|
33
|
+
when 2 then event_v2
|
34
|
+
else raise ArgumentError, "Unknown event message version #{message_version}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def command_builder
|
39
|
+
case message_version
|
40
|
+
when 1 then command_v1
|
41
|
+
when 2 then command_v2
|
42
|
+
else raise ArgumentError, "Unknown command message version #{message_version}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def event_v1
|
47
|
+
Messages::V1::Event.wrap(message_without_kind)
|
48
|
+
end
|
49
|
+
|
50
|
+
def event_v2
|
51
|
+
Messages::V2::Event.wrap(message_without_kind)
|
52
|
+
end
|
53
|
+
|
54
|
+
def command_v1
|
55
|
+
Messages::V1::Command.wrap(message_without_kind)
|
56
|
+
end
|
57
|
+
|
58
|
+
def command_v2
|
59
|
+
Messages::V2::Command.wrap(message_without_kind)
|
60
|
+
end
|
61
|
+
|
62
|
+
def message_version
|
63
|
+
Integer(@raw_message[:version])
|
64
|
+
end
|
65
|
+
|
66
|
+
def message_without_kind
|
67
|
+
@raw_message.except(:kind)
|
68
|
+
end
|
69
|
+
|
70
|
+
def kind
|
71
|
+
return @raw_message[:kind] if @raw_message[:kind]
|
72
|
+
|
73
|
+
@raw_message[:type].split('_').first
|
74
|
+
end
|
75
|
+
|
76
|
+
def message_type
|
77
|
+
return @raw_message[:type] if @raw_message[:kind]
|
78
|
+
|
79
|
+
@raw_message[:type].gsub(/^(event_|command_)/, '')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cyclone_lariat/messages/abstract'
|
4
|
+
|
5
|
+
module CycloneLariat
|
6
|
+
module Messages
|
7
|
+
class Common < Abstract
|
8
|
+
KIND = 'unknown'
|
9
|
+
|
10
|
+
attrs :subject, :object
|
11
|
+
|
12
|
+
def kind
|
13
|
+
KIND
|
14
|
+
end
|
15
|
+
|
16
|
+
def serialize
|
17
|
+
{
|
18
|
+
uuid: uuid,
|
19
|
+
publisher: publisher,
|
20
|
+
type: [kind, type].join('_'),
|
21
|
+
version: version,
|
22
|
+
data: data,
|
23
|
+
request_id: request_id,
|
24
|
+
sent_at: sent_at&.iso8601(3),
|
25
|
+
subject: subject,
|
26
|
+
object: object
|
27
|
+
}.compact
|
28
|
+
end
|
29
|
+
|
30
|
+
def subject
|
31
|
+
@subject ||= {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def object
|
35
|
+
@object ||= {}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'cyclone_lariat/messages/
|
3
|
+
require 'cyclone_lariat/messages/abstract'
|
4
|
+
require 'cyclone_lariat/messages/v1/validator'
|
4
5
|
|
5
6
|
module CycloneLariat
|
6
7
|
module Messages
|
7
8
|
module V1
|
8
9
|
class Command < Abstract
|
9
|
-
|
10
|
-
validator Messages::V1::Validator
|
10
|
+
validator Validator
|
11
11
|
|
12
12
|
KIND = 'command'
|
13
13
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'cyclone_lariat/messages/
|
3
|
+
require 'cyclone_lariat/messages/abstract'
|
4
|
+
require 'cyclone_lariat/messages/v1/validator'
|
4
5
|
|
5
6
|
module CycloneLariat
|
6
7
|
module Messages
|
7
8
|
module V1
|
8
9
|
class Event < Abstract
|
9
|
-
|
10
|
-
validator Messages::V1::Validator
|
10
|
+
validator Validator
|
11
11
|
|
12
12
|
KIND = 'event'
|
13
13
|
|
@@ -1,19 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'cyclone_lariat/messages/
|
3
|
+
require 'cyclone_lariat/messages/abstract'
|
4
|
+
require 'cyclone_lariat/messages/v2/validator'
|
4
5
|
|
5
6
|
module CycloneLariat
|
6
7
|
module Messages
|
7
8
|
module V2
|
8
9
|
class Command < Abstract
|
9
|
-
|
10
|
-
|
10
|
+
validator Validator
|
11
|
+
|
12
|
+
attrs :subject, :object
|
11
13
|
|
12
14
|
KIND = 'command'
|
13
15
|
|
14
16
|
def kind
|
15
17
|
KIND
|
16
18
|
end
|
19
|
+
|
20
|
+
def serialize
|
21
|
+
{
|
22
|
+
uuid: uuid,
|
23
|
+
publisher: publisher,
|
24
|
+
type: [kind, type].join('_'),
|
25
|
+
version: version,
|
26
|
+
data: data,
|
27
|
+
request_id: request_id,
|
28
|
+
sent_at: sent_at&.iso8601(3),
|
29
|
+
subject: subject,
|
30
|
+
object: object
|
31
|
+
}.compact
|
32
|
+
end
|
33
|
+
|
34
|
+
def subject
|
35
|
+
@subject ||= {}
|
36
|
+
end
|
37
|
+
|
38
|
+
def object
|
39
|
+
@object ||= {}
|
40
|
+
end
|
17
41
|
end
|
18
42
|
end
|
19
43
|
end
|
@@ -1,19 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'cyclone_lariat/messages/
|
3
|
+
require 'cyclone_lariat/messages/abstract'
|
4
|
+
require 'cyclone_lariat/messages/v2/validator'
|
4
5
|
|
5
6
|
module CycloneLariat
|
6
7
|
module Messages
|
7
8
|
module V2
|
8
9
|
class Event < Abstract
|
9
|
-
|
10
|
-
|
10
|
+
validator Validator
|
11
|
+
|
12
|
+
attrs :subject, :object
|
11
13
|
|
12
14
|
KIND = 'event'
|
13
15
|
|
14
16
|
def kind
|
15
17
|
KIND
|
16
18
|
end
|
19
|
+
|
20
|
+
def serialize
|
21
|
+
{
|
22
|
+
uuid: uuid,
|
23
|
+
publisher: publisher,
|
24
|
+
type: [kind, type].join('_'),
|
25
|
+
version: version,
|
26
|
+
data: data,
|
27
|
+
request_id: request_id,
|
28
|
+
sent_at: sent_at&.iso8601(3),
|
29
|
+
subject: subject,
|
30
|
+
object: object
|
31
|
+
}.compact
|
32
|
+
end
|
33
|
+
|
34
|
+
def subject
|
35
|
+
@subject ||= {}
|
36
|
+
end
|
37
|
+
|
38
|
+
def object
|
39
|
+
@object ||= {}
|
40
|
+
end
|
17
41
|
end
|
18
42
|
end
|
19
43
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'cyclone_lariat/repo/messages'
|
4
4
|
require 'cyclone_lariat/core'
|
5
5
|
require 'luna_park/errors'
|
6
|
+
require 'cyclone_lariat/messages/builder'
|
6
7
|
require 'json'
|
7
8
|
|
8
9
|
module CycloneLariat
|
@@ -23,7 +24,7 @@ module CycloneLariat
|
|
23
24
|
return if msg.is_a? String
|
24
25
|
|
25
26
|
catch_standard_error(queue, msg) do
|
26
|
-
event = Messages::
|
27
|
+
event = Messages::Builder.new(raw_message: msg).call
|
27
28
|
|
28
29
|
store_in_dataset(event) do
|
29
30
|
catch_business_error(event, &block)
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'cyclone_lariat/messages/v1/event'
|
4
4
|
require 'cyclone_lariat/messages/v1/command'
|
5
5
|
require 'cyclone_lariat/repo/messages_mapper'
|
6
|
+
require 'cyclone_lariat/messages/builder'
|
6
7
|
|
7
8
|
module CycloneLariat
|
8
9
|
module Repo
|
@@ -80,11 +81,7 @@ module CycloneLariat
|
|
80
81
|
end
|
81
82
|
|
82
83
|
def build(raw)
|
83
|
-
|
84
|
-
when 'event' then CycloneLariat::Messages::V1::Event.wrap raw
|
85
|
-
when 'command' then CycloneLariat::Messages::V1::Command.wrap raw
|
86
|
-
else raise ArgumentError, "Unknown kind `#{kind}` of message"
|
87
|
-
end
|
84
|
+
CycloneLariat::Messages::Builder.new(raw_message: raw).call
|
88
85
|
end
|
89
86
|
end
|
90
87
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'cyclone_lariat/messages/v1/event'
|
4
4
|
require 'cyclone_lariat/messages/v1/command'
|
5
5
|
require 'cyclone_lariat/repo/messages_mapper'
|
6
|
+
require 'cyclone_lariat/messages/builder'
|
6
7
|
|
7
8
|
module CycloneLariat
|
8
9
|
module Repo
|
@@ -61,11 +62,7 @@ module CycloneLariat
|
|
61
62
|
private
|
62
63
|
|
63
64
|
def build(raw)
|
64
|
-
|
65
|
-
when 'event' then CycloneLariat::Messages::V1::Event.wrap raw
|
66
|
-
when 'command' then CycloneLariat::Messages::V1::Command.wrap raw
|
67
|
-
else raise ArgumentError, "Unknown kind `#{kind}` of message"
|
68
|
-
end
|
65
|
+
CycloneLariat::Messages::Builder.new(raw_message: raw).call
|
69
66
|
end
|
70
67
|
end
|
71
68
|
end
|
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: 1.0.0.
|
4
|
+
version: 1.0.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kudrin
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2023-
|
14
|
+
date: 2023-02-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: aws-sdk-sns
|
@@ -388,11 +388,12 @@ files:
|
|
388
388
|
- lib/cyclone_lariat/generators/event.rb
|
389
389
|
- lib/cyclone_lariat/generators/queue.rb
|
390
390
|
- lib/cyclone_lariat/generators/topic.rb
|
391
|
-
- lib/cyclone_lariat/messages/
|
391
|
+
- lib/cyclone_lariat/messages/abstract.rb
|
392
|
+
- lib/cyclone_lariat/messages/builder.rb
|
393
|
+
- lib/cyclone_lariat/messages/common.rb
|
392
394
|
- lib/cyclone_lariat/messages/v1/command.rb
|
393
395
|
- lib/cyclone_lariat/messages/v1/event.rb
|
394
396
|
- lib/cyclone_lariat/messages/v1/validator.rb
|
395
|
-
- lib/cyclone_lariat/messages/v2/abstract.rb
|
396
397
|
- lib/cyclone_lariat/messages/v2/command.rb
|
397
398
|
- lib/cyclone_lariat/messages/v2/event.rb
|
398
399
|
- lib/cyclone_lariat/messages/v2/validator.rb
|
@@ -1,139 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'luna_park/entities/attributable'
|
4
|
-
require 'luna_park/extensions/validatable'
|
5
|
-
require 'cyclone_lariat/messages/v1/validator'
|
6
|
-
require 'cyclone_lariat/errors'
|
7
|
-
|
8
|
-
module CycloneLariat
|
9
|
-
module Messages
|
10
|
-
module V1
|
11
|
-
class Abstract < LunaPark::Entities::Attributable
|
12
|
-
include LunaPark::Extensions::Validatable
|
13
|
-
|
14
|
-
attr :uuid, String, :new
|
15
|
-
attr :publisher, String, :new
|
16
|
-
attr :type, String, :new
|
17
|
-
|
18
|
-
attrs :client_error, :version, :data, :request_id, :sent_at,
|
19
|
-
:deduplication_id, :group_id, :processed_at, :received_at
|
20
|
-
|
21
|
-
validator Validator
|
22
|
-
|
23
|
-
# Make validation public
|
24
|
-
def validation
|
25
|
-
super
|
26
|
-
end
|
27
|
-
|
28
|
-
def serialize
|
29
|
-
{
|
30
|
-
uuid: uuid,
|
31
|
-
publisher: publisher,
|
32
|
-
type: [kind, type].join('_'),
|
33
|
-
version: version,
|
34
|
-
data: data,
|
35
|
-
request_id: request_id,
|
36
|
-
sent_at: sent_at&.iso8601(3)
|
37
|
-
}.compact
|
38
|
-
end
|
39
|
-
|
40
|
-
def to_json(*args)
|
41
|
-
serialize.to_json(*args)
|
42
|
-
end
|
43
|
-
|
44
|
-
alias params serialize
|
45
|
-
|
46
|
-
def kind
|
47
|
-
raise LunaPark::Errors::AbstractMethod
|
48
|
-
end
|
49
|
-
|
50
|
-
def data
|
51
|
-
@data ||= {}
|
52
|
-
end
|
53
|
-
|
54
|
-
def version=(value)
|
55
|
-
@version = Integer(value)
|
56
|
-
end
|
57
|
-
|
58
|
-
def sent_at=(value)
|
59
|
-
@sent_at = wrap_time(value)
|
60
|
-
end
|
61
|
-
|
62
|
-
def received_at=(value)
|
63
|
-
@received_at = wrap_time(value)
|
64
|
-
end
|
65
|
-
|
66
|
-
def processed_at=(value)
|
67
|
-
@processed_at = wrap_time(value)
|
68
|
-
end
|
69
|
-
|
70
|
-
def request_id=(value)
|
71
|
-
@request_id = wrap_string(value)
|
72
|
-
end
|
73
|
-
|
74
|
-
def group_id=(value)
|
75
|
-
@group_id = wrap_string(value)
|
76
|
-
end
|
77
|
-
|
78
|
-
def deduplication_id=(value)
|
79
|
-
@deduplication_id = wrap_string(value)
|
80
|
-
end
|
81
|
-
|
82
|
-
def processed?
|
83
|
-
!@processed_at.nil?
|
84
|
-
end
|
85
|
-
|
86
|
-
def client_error_message=(txt)
|
87
|
-
return unless txt
|
88
|
-
|
89
|
-
@client_error ||= Errors::ClientError.new
|
90
|
-
@client_error.message = txt
|
91
|
-
end
|
92
|
-
|
93
|
-
def client_error_details=(details)
|
94
|
-
return unless details
|
95
|
-
|
96
|
-
@client_error ||= Errors::ClientError.new
|
97
|
-
@client_error.details = details
|
98
|
-
end
|
99
|
-
|
100
|
-
def fifo?
|
101
|
-
!@group_id.nil?
|
102
|
-
end
|
103
|
-
|
104
|
-
def ==(other)
|
105
|
-
kind == other.kind &&
|
106
|
-
uuid == other.uuid &&
|
107
|
-
publisher == other.publisher &&
|
108
|
-
type == other.type &&
|
109
|
-
client_error&.message == other.client_error&.message &&
|
110
|
-
version == other.version &&
|
111
|
-
sent_at.to_i == other.sent_at.to_i &&
|
112
|
-
received_at.to_i == other.received_at.to_i &&
|
113
|
-
processed_at.to_i == other.processed_at.to_i
|
114
|
-
end
|
115
|
-
|
116
|
-
private
|
117
|
-
|
118
|
-
def wrap_time(value)
|
119
|
-
case value
|
120
|
-
when String then Time.parse(value)
|
121
|
-
when Time then value
|
122
|
-
when NilClass then nil
|
123
|
-
else raise ArgumentError, "Unknown type `#{value.class}`"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def wrap_string(value)
|
128
|
-
case value
|
129
|
-
when String then String(value)
|
130
|
-
when Integer then String(value)
|
131
|
-
when NilClass then nil
|
132
|
-
when FalseClass then nil
|
133
|
-
else raise ArgumentError, "Unknown type `#{value.class}`"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
@@ -1,149 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'luna_park/entities/attributable'
|
4
|
-
require 'luna_park/extensions/validatable'
|
5
|
-
require 'cyclone_lariat/messages/v2/validator'
|
6
|
-
require 'cyclone_lariat/errors'
|
7
|
-
|
8
|
-
module CycloneLariat
|
9
|
-
module Messages
|
10
|
-
module V2
|
11
|
-
class Abstract < LunaPark::Entities::Attributable
|
12
|
-
include LunaPark::Extensions::Validatable
|
13
|
-
|
14
|
-
attr :uuid, String, :new
|
15
|
-
attr :publisher, String, :new
|
16
|
-
attr :type, String, :new
|
17
|
-
attrs :client_error, :version, :data, :request_id, :sent_at,
|
18
|
-
:deduplication_id, :group_id, :processed_at, :received_at,
|
19
|
-
:subject, :object
|
20
|
-
|
21
|
-
validator Validator
|
22
|
-
|
23
|
-
# Make validation public
|
24
|
-
def validation
|
25
|
-
super
|
26
|
-
end
|
27
|
-
|
28
|
-
def serialize
|
29
|
-
{
|
30
|
-
uuid: uuid,
|
31
|
-
publisher: publisher,
|
32
|
-
type: [kind, type].join('_'),
|
33
|
-
version: version,
|
34
|
-
data: data,
|
35
|
-
request_id: request_id,
|
36
|
-
sent_at: sent_at&.iso8601(3),
|
37
|
-
subject: subject,
|
38
|
-
object: object
|
39
|
-
}.compact
|
40
|
-
end
|
41
|
-
|
42
|
-
def to_json(*args)
|
43
|
-
serialize.to_json(*args)
|
44
|
-
end
|
45
|
-
|
46
|
-
alias params serialize
|
47
|
-
|
48
|
-
def kind
|
49
|
-
raise LunaPark::Errors::AbstractMethod
|
50
|
-
end
|
51
|
-
|
52
|
-
def data
|
53
|
-
@data ||= {}
|
54
|
-
end
|
55
|
-
|
56
|
-
def subject
|
57
|
-
@subject ||= {}
|
58
|
-
end
|
59
|
-
|
60
|
-
def object
|
61
|
-
@object ||= {}
|
62
|
-
end
|
63
|
-
|
64
|
-
def version=(value)
|
65
|
-
@version = Integer(value)
|
66
|
-
end
|
67
|
-
|
68
|
-
def sent_at=(value)
|
69
|
-
@sent_at = wrap_time(value)
|
70
|
-
end
|
71
|
-
|
72
|
-
def received_at=(value)
|
73
|
-
@received_at = wrap_time(value)
|
74
|
-
end
|
75
|
-
|
76
|
-
def processed_at=(value)
|
77
|
-
@processed_at = wrap_time(value)
|
78
|
-
end
|
79
|
-
|
80
|
-
def request_id=(value)
|
81
|
-
@request_id = wrap_string(value)
|
82
|
-
end
|
83
|
-
|
84
|
-
def group_id=(value)
|
85
|
-
@group_id = wrap_string(value)
|
86
|
-
end
|
87
|
-
|
88
|
-
def deduplication_id=(value)
|
89
|
-
@deduplication_id = wrap_string(value)
|
90
|
-
end
|
91
|
-
|
92
|
-
def processed?
|
93
|
-
!@processed_at.nil?
|
94
|
-
end
|
95
|
-
|
96
|
-
def client_error_message=(txt)
|
97
|
-
return unless txt
|
98
|
-
|
99
|
-
@client_error ||= Errors::ClientError.new
|
100
|
-
@client_error.message = txt
|
101
|
-
end
|
102
|
-
|
103
|
-
def client_error_details=(details)
|
104
|
-
return unless details
|
105
|
-
|
106
|
-
@client_error ||= Errors::ClientError.new
|
107
|
-
@client_error.details = details
|
108
|
-
end
|
109
|
-
|
110
|
-
def fifo?
|
111
|
-
!@group_id.nil?
|
112
|
-
end
|
113
|
-
|
114
|
-
def ==(other)
|
115
|
-
kind == other.kind &&
|
116
|
-
uuid == other.uuid &&
|
117
|
-
publisher == other.publisher &&
|
118
|
-
type == other.type &&
|
119
|
-
client_error&.message == other.client_error&.message &&
|
120
|
-
version == other.version &&
|
121
|
-
sent_at.to_i == other.sent_at.to_i &&
|
122
|
-
received_at.to_i == other.received_at.to_i &&
|
123
|
-
processed_at.to_i == other.processed_at.to_i
|
124
|
-
end
|
125
|
-
|
126
|
-
private
|
127
|
-
|
128
|
-
def wrap_time(value)
|
129
|
-
case value
|
130
|
-
when String then Time.parse(value)
|
131
|
-
when Time then value
|
132
|
-
when NilClass then nil
|
133
|
-
else raise ArgumentError, "Unknown type `#{value.class}`"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def wrap_string(value)
|
138
|
-
case value
|
139
|
-
when String then String(value)
|
140
|
-
when Integer then String(value)
|
141
|
-
when NilClass then nil
|
142
|
-
when FalseClass then nil
|
143
|
-
else raise ArgumentError, "Unknown type `#{value.class}`"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|