cyclone_lariat 1.0.0.rc1 → 1.0.0.rc3

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: 31cc88737fffda51fb2ba2f1ef8ea792adcd3d7d
4
- data.tar.gz: 520aef70c935d03db0f7624a253f62ac6dddeaa7
3
+ metadata.gz: c2611c13c5fb86d9aa353ae3df16d5c216fb02be
4
+ data.tar.gz: b90c6880d34961111dc73cb9f794561fa2a42630
5
5
  SHA512:
6
- metadata.gz: 062f76a7ef10d61bd94e624e4db72619ace3bf3d7ee05ab0ec7b32ecbca8895afda9dc060390aa0c157e1ae843a6e6bce99e815a965c6fde3e49655e9ceb3709
7
- data.tar.gz: 91adda66efabdd82c60e2e1fb2f1a602a4b3c6f26300c5d3c82ac923466024fee705d5012d5c9cecae671081af0c91cbda52291ef3e896f4d182914f3f125ec1
6
+ metadata.gz: '092ed1050daccad64005c8c91d586057f011881ddc3564f60892f27951b67b5e4f038730143273dd724e7792310206aab0c77ab09500f13933573fb0b03590b9'
7
+ data.tar.gz: 8b2b9d21456541871afd95dfd0b20057bdcdea543dce49b5ad34a66eb026067ef3869ae785b3962334783e371b293d8f3daf0eec9b7766ce112cbb43235e6d12
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ 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
+
11
+ ## [1.0.0.rc2]
12
+ Changed
13
+ - README.md file
14
+ Added
15
+ - require version file, fixed `bundle exec cyclone_lariat -v`
16
+
7
17
  ## [0.4.0]
8
18
  Changed
9
19
  - rename `topic` to `queue` for SQS operations, in fact it changed only in methods `publish_event`, `publish_command`
@@ -19,7 +29,7 @@ Added
19
29
  Added
20
30
  - Added aws_client_od options
21
31
  Changed:
22
- - Renamed all AWS options with prefix _aws
32
+ - Renamed all AWS options with prefix _aws
23
33
 
24
34
  ## [0.3.9] - 2022-10-05 Depricated
25
35
  Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cyclone_lariat (1.0.0.rc1)
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.694.0)
32
- aws-sdk-core (3.168.4)
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.57.0)
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.52.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)
data/README.md CHANGED
@@ -24,7 +24,7 @@ This gem work in few scenarios:
24
24
  And run in console:
25
25
  ```bash
26
26
  $ bundle install
27
- $ cyclone_lariat install
27
+ $ bundle exec cyclone_lariat install
28
28
  ```
29
29
  </details>
30
30
  <details>
@@ -40,7 +40,7 @@ This gem work in few scenarios:
40
40
  And run in console:
41
41
  ```bash
42
42
  $ bundle install
43
- $ cyclone_lariat install --adapter=active_record
43
+ $ bundle exec cyclone_lariat install --adapter=active_record
44
44
  ```
45
45
  </details>
46
46
 
@@ -344,7 +344,7 @@ class Publisher < CycloneLariat::Publisher
344
344
  def delete_user(mail)
345
345
  sns.publish command('delete_user', data: { mail: mail }), fifo: false
346
346
  end
347
-
347
+
348
348
  def welcome_message(mail, text)
349
349
  sqs.publish command('welcome', data: {mail: mail, txt: text}), fifo: false
350
350
  end
@@ -408,13 +408,13 @@ CycloneLariat::Clients::Sns.new.publish_command(
408
408
  class Publisher < CycloneLariat::Publisher
409
409
  def register_user(first:, last:, mail:)
410
410
  sns.publish command(
411
- 'register_user',
412
- data: {
413
- mail: mail,
411
+ 'register_user',
412
+ data: {
413
+ mail: mail,
414
414
  name: {
415
- first: first,
415
+ first: first,
416
416
  last: last
417
- }
417
+ }
418
418
  }
419
419
  ), fifo: false
420
420
  end
@@ -482,16 +482,16 @@ end
482
482
  Will publish message on queue: `custom_topic_name`
483
483
 
484
484
 
485
- ### FIFO and no FIFO
485
+ ### FIFO and no FIFO
486
486
  The main idea you can read on [AWS Docs](https://aws.amazon.com/blogs/aws/introducing-amazon-sns-fifo-first-in-first-out-pub-sub-messaging/).
487
487
 
488
488
  FIFO message should consist two fields:
489
- - `group_id` - In each topic, the FIFO sequence is defined only within one group.
489
+ - `group_id` - In each topic, the FIFO sequence is defined only within one group.
490
490
  [AWS Docs](https://docs.aws.amazon.com/sns/latest/dg/fifo-message-grouping.html)
491
- - `deduplication_id` - Within the same group, a unique identifier must be defined for each message.
491
+ - `deduplication_id` - Within the same group, a unique identifier must be defined for each message.
492
492
  [AWS Docs](https://docs.aws.amazon.com/sns/latest/dg/fifo-message-dedup.html)
493
-
494
- The unique identifier can definitely be the entire message. In this case, you
493
+
494
+ The unique identifier can definitely be the entire message. In this case, you
495
495
  do not need to pass the deduplication_id parameter. But you must create a queue
496
496
  with the `content_based_deduplication` parameter in migration.
497
497
 
@@ -516,7 +516,7 @@ class Publisher < CycloneLariat::Publisher
516
516
  uuid: uuid,
517
517
  mail: mail
518
518
  },
519
- },
519
+ },
520
520
  deduplication_id: mail,
521
521
  group_id: uuid),
522
522
  fifo: true
@@ -541,7 +541,7 @@ With **cyclone_lariat** you can use migrations that can create, delete, and subs
541
541
  Before using this function, you must complete the **cyclone_lariat** [configuration](#Configuration).
542
542
 
543
543
  ```bash
544
- $ cyclone_lariat generate migration user_created
544
+ $ bundle exec cyclone_lariat generate migration user_created
545
545
  ```
546
546
 
547
547
  This command should create a migration file, let's edit it.
@@ -561,7 +561,7 @@ class UserCreatedQueue < CycloneLariat::Migration
561
561
  end
562
562
  end
563
563
  ```
564
- The `content_based_dedupplication` parameter can only be specified for FIFO resources. When true, the whole message is
564
+ The `content_based_dedupplication` parameter can only be specified for FIFO resources. When true, the whole message is
565
565
  used as the unique message identifier instead of the `deduplication_id` key.
566
566
 
567
567
  To apply migration use:
@@ -720,8 +720,8 @@ We recommend locate migration on:
720
720
  ## Console tasks
721
721
 
722
722
  ```bash
723
- $ cyclone_lariat install - install cyclone_lariat
724
- $ cyclone_lariat generate migration - generate new migration
723
+ $ bundle exec cyclone_lariat install - install cyclone_lariat
724
+ $ bundle exec cyclone_lariat generate migration - generate new migration
725
725
 
726
726
  $ rake cyclone_lariat:list:queues # List all queues
727
727
  $ rake cyclone_lariat:list:subscriptions # List all subscriptions
@@ -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/v1/abstract'
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
- include LunaPark::Extensions::Validatable
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/v1/abstract'
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
- include LunaPark::Extensions::Validatable
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/v2/abstract'
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
- include LunaPark::Extensions::Validatable
10
- validator Messages::V2::Validator
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/v2/abstract'
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
- include LunaPark::Extensions::Validatable
10
- validator Messages::V2::Validator
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::V1::Event.wrap(msg)
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
- case kind = raw.delete(:kind)
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
- case kind = raw.delete(:kind)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CycloneLariat
4
- VERSION = '1.0.0.rc1'
4
+ VERSION = '1.0.0.rc3'
5
5
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cyclone_lariat/version'
3
4
  require 'cyclone_lariat/core'
4
5
  require 'cyclone_lariat/middleware'
5
6
  require 'cyclone_lariat/migration'
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.rc1
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-01-30 00:00:00.000000000 Z
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/v1/abstract.rb
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