evt-consumer-postgres 1.0.1.0 → 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
  SHA256:
3
- metadata.gz: 8b9e728d8d64095daf2e0e8b4c257a33442d3fee6aa04796cf3261371b4b9c23
4
- data.tar.gz: eef0e89380daecf69c95c13b4d47d5c594201fd22c7ab0be021427652ed4ba53
3
+ metadata.gz: 0c6bbee96c4b1ea1137efe3557dd3392c04b6c3389f87b66d67235a22eedb358
4
+ data.tar.gz: c93756676d9dadcfaa6311ebde4e58bd3343872b49baefaa4804d45f693af754
5
5
  SHA512:
6
- metadata.gz: 196daa0e73fce6a1d842db093d6bba4f8811977b313befb7cc8ae67ed68ea7a686335665892db021045a411c9c1cdbaaa55bfa86c3237af84f5039ed482f4db1
7
- data.tar.gz: f479fd56d52159824c1e8c7d1bf0528f950ca5ffa37633cdb8a504f73369cbce88705177f4f1a976c2afce25528c7e1e9150a7c121c5f377e53f6c483de60b2b
6
+ metadata.gz: dc8bbb6fcd8befb11a287ed88f48e0da55fea427e11003f3321ee69bf2c49902f6f4372cd8026a993705a11a03096abcaa1ca61d180ca95d0f10e349965c8bce
7
+ data.tar.gz: 31d603dead6e7c0dbac11be9040566d3bc5415a2c9bf7d11893ca889d37a488e5f29c2c8664c636bd1684b5e17fdf278f09f3cd73c3cac1b8b12422449dec5f6
@@ -8,6 +8,12 @@ module Consumer
8
8
  end
9
9
  end
10
10
 
11
+ module ConsumerGroup
12
+ def self.example(group_size:, group_member:)
13
+ "@hash_64(stream_name) % #{group_size} = #{group_member}"
14
+ end
15
+ end
16
+
11
17
  module Ordinary
12
18
  def self.example
13
19
  'some condition'
@@ -5,8 +5,10 @@ module Consumer
5
5
  include ::Consumer
6
6
 
7
7
  attr_accessor :batch_size
8
- attr_accessor :condition
9
8
  attr_accessor :correlation
9
+ attr_accessor :group_size
10
+ attr_accessor :group_member
11
+ attr_accessor :condition
10
12
  attr_accessor :composed_condition
11
13
  end
12
14
  end
@@ -20,8 +22,12 @@ module Consumer
20
22
  logger.info(tag: :*) { "Correlation: #{correlation}" }
21
23
  end
22
24
 
25
+ unless group_size.nil? && group_member.nil?
26
+ logger.info(tag: :*) { "Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect}" }
27
+ end
28
+
23
29
  unless condition.nil?
24
- logger.info(tag: :*) { "Condition: #{composed_condition}" }
30
+ logger.info(tag: :*) { "Condition: #{condition}" }
25
31
  end
26
32
 
27
33
  unless composed_condition.nil?
@@ -29,11 +35,13 @@ module Consumer
29
35
  end
30
36
  end
31
37
 
32
- def configure(batch_size: nil, settings: nil, correlation: nil, condition: nil)
33
- composed_condition = Condition.compose(correlation: correlation, condition: condition)
38
+ def configure(batch_size: nil, settings: nil, correlation: nil, group_size: nil, group_member: nil, condition: nil)
39
+ composed_condition = Condition.compose(correlation: correlation, group_size: group_size, group_member: group_member, condition: condition)
34
40
 
35
41
  self.batch_size = batch_size
36
42
  self.correlation = correlation
43
+ self.group_size = group_size
44
+ self.group_member = group_member
37
45
  self.condition = condition
38
46
  self.composed_condition = composed_condition
39
47
 
@@ -60,7 +68,7 @@ module Consumer
60
68
  module Condition
61
69
  extend self
62
70
 
63
- def compose(condition: nil, correlation: nil)
71
+ def compose(condition: nil, correlation: nil, group_size: nil, group_member: nil)
64
72
  composed_condition = []
65
73
 
66
74
  unless condition.nil?
@@ -69,10 +77,14 @@ module Consumer
69
77
 
70
78
  unless correlation.nil?
71
79
  Correlation.assure(correlation)
72
-
73
80
  composed_condition << "metadata->>'correlationStreamName' like '#{correlation}-%'"
74
81
  end
75
82
 
83
+ unless group_size.nil? && group_member.nil?
84
+ Group.assure(group_size, group_member)
85
+ composed_condition << "@hash_64(stream_name) % #{group_size} = #{group_member}"
86
+ end
87
+
76
88
  return nil if composed_condition.empty?
77
89
 
78
90
  sql_condition = composed_condition.join(' AND ')
@@ -90,5 +102,33 @@ module Consumer
90
102
  end
91
103
  end
92
104
  end
105
+
106
+ module Group
107
+ Error = Class.new(RuntimeError)
108
+
109
+ def self.assure(group_size, group_member)
110
+ error_message = 'Consumer group definition is incorrect.'
111
+
112
+ arguments_count = [group_size, group_member].compact.length
113
+
114
+ if arguments_count == 1
115
+ raise Error, "#{error_message} Group size and group member are both required. (Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect})"
116
+ end
117
+
118
+ return if arguments_count == 0
119
+
120
+ if group_size < 1
121
+ raise Error, "#{error_message} Group size must not be less than 1. (Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect})"
122
+ end
123
+
124
+ if group_member < 0
125
+ raise Error, "#{error_message} Group member must not be less than 0. (Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect})"
126
+ end
127
+
128
+ if group_member >= group_size
129
+ raise Error, "#{error_message} Group member must be at least one less than group size. (Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect})"
130
+ end
131
+ end
132
+ end
93
133
  end
94
134
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-consumer-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.0
4
+ version: 1.0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-30 00:00:00.000000000 Z
11
+ date: 2019-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-consumer
@@ -95,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubyforge_project:
99
- rubygems_version: 2.7.3
98
+ rubygems_version: 3.0.1
100
99
  signing_key:
101
100
  specification_version: 4
102
101
  summary: Postgres implementation of continuous subscription to a stream and message