messaging 3.4.2 → 3.4.3

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: 4e2d081991ad2e8413244571ae8c9f9d3d3d5af9ce48bfcbff424e968c1d5c18
4
- data.tar.gz: 8ca81941ebd45f6daad6a6c08435598a8b9f0bd3dede7fb99e9cc859a56bb6de
3
+ metadata.gz: 30a2583692555ea89d81c50ea5cbf03f21763c3e030ceded07ecbf2f46335015
4
+ data.tar.gz: 61164fd9cc9bae8acffe8094bcfcf3dfd4ca2d39fb03f279488d64f5e8a212e8
5
5
  SHA512:
6
- metadata.gz: d932b1bfe5c5456e681c21280efbb055eb12acd6bcf5358dfe36d7afaca1bae61da98fbc994ea830a68c2db91230ef6883182b86d482201ae5242f38d19b3280
7
- data.tar.gz: 6bcf879f6c3a9f2e8353c8877c81340d64e7418b85c84a9003337927402314d4a2cc3b6d279faf25b0ba1d0209a45ef510dd9067cc23bf48cc60a1bd0ab3852c
6
+ metadata.gz: bd04d056d7dd80c5b7a79d0ff999c5feefb0e1f77e176f9b13c8931b1b439bb3d7ade1746ad951c7e43d43d96d439909c79b190c423fdaf11cd195870b896b71
7
+ data.tar.gz: ffc5d6ba0b9801ca7ef4f55232815c0719c10e8c7e2d27fa8a6f94a1109d195143ee43c861372c92f33c7e7e9ef99f1674ab00ccb87a8b39d8b50e9b69916945
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ Gemfile.lock
data/Gemfile CHANGED
@@ -3,8 +3,6 @@ source 'https://rubygems.org'
3
3
  git_source(:github) { |path| "https://github.com/#{path}.git" }
4
4
 
5
5
  gem 'bootsnap', require: false
6
- gem 'bukowskis_after_transaction', github: 'bukowskis/after_transaction'
7
- gem 'bukowskis_method_object', github: 'bukowskis/method_object'
8
6
  gem 'listen'
9
7
  gem 'pg'
10
8
  gem 'pry'
@@ -53,6 +53,10 @@ module Messaging
53
53
  @routes ||= Routes.new
54
54
  end
55
55
 
56
+ def self.category(name)
57
+ message_store.category(name)
58
+ end
59
+
56
60
  def self.stream(name)
57
61
  name = name.stream_name if name.respond_to?(:stream_name)
58
62
  message_store.stream(name)
@@ -0,0 +1,27 @@
1
+ module Messaging
2
+ module Adapters
3
+ class Postgres
4
+ class Categories
5
+ include Enumerable
6
+
7
+ def each
8
+ return enum_for(:each) unless block_given?
9
+
10
+ all_categories.each do |name|
11
+ yield Category.new(name)
12
+ end
13
+ end
14
+
15
+ def [](name)
16
+ Category.new(name)
17
+ end
18
+
19
+ private
20
+
21
+ def all_categories
22
+ SerializedMessage.distinct.pluck(:stream_category).lazy
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,40 @@
1
+ module Messaging
2
+ module Adapters
3
+ class Postgres
4
+ class Category
5
+ # @return [String] the name of the category
6
+ attr_reader :name
7
+
8
+ # Should not be used directly.
9
+ # Use {Messaging.category} or {Store#category}
10
+ # @api private
11
+ # @see Messaging.category
12
+ # @see Store.category
13
+ def initialize(name)
14
+ @name = name
15
+ end
16
+
17
+ # Access to all messages in the category sorted by created_at
18
+ # @return [ActiveRecord::Relation]
19
+ def messages
20
+ SerializedMessage.where(stream_category: name).order(:created_at)
21
+ end
22
+
23
+ def messages_older_than(time)
24
+ messages.where('created_at < ?', time)
25
+ end
26
+
27
+ def delete_messages_older_than!(time)
28
+ SerializedMessage.transaction do
29
+ ActiveRecord::Base.connection.execute "SET LOCAL statement_timeout = '0'"
30
+ messages_older_than(time).delete_all
31
+ end
32
+ end
33
+
34
+ def inspect
35
+ "#<Category:#{name}>>"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -23,7 +23,8 @@ module Messaging
23
23
  self.expected_version = message.expected_version
24
24
  self.message_type = message.message_type
25
25
  self.stream = message.stream_name
26
- self.stream_category, self.stream_id = message.stream_name.split('$')
26
+ self.stream_category = message.stream_category
27
+ self.stream_id = message.stream_id
27
28
  self.uuid = message.uuid
28
29
  end
29
30
 
@@ -1,3 +1,5 @@
1
+ require_relative 'category'
2
+ require_relative 'categories'
1
3
  require_relative 'stream'
2
4
  require_relative 'streams'
3
5
 
@@ -20,11 +22,16 @@ module Messaging
20
22
  # @see Streams
21
23
  attr_reader :streams
22
24
 
25
+ # @return [Categories] all the stream categories in the store
26
+ # @see Categories
27
+ attr_reader :categories
28
+
23
29
  # Should not be used directly. Access the store though
24
30
  # Messaging.message_store or Messaging::Adapters::Store[:postgres]
25
31
  # @api private
26
32
  def initialize
27
33
  @streams = Streams.new
34
+ @categories = Categories.new
28
35
  end
29
36
 
30
37
  # Get a specific stream by name
@@ -34,6 +41,13 @@ module Messaging
34
41
  streams[name]
35
42
  end
36
43
 
44
+ # Get a specific category by name
45
+ # @return [Stream]
46
+ # @see Messaging.category
47
+ def category(name)
48
+ categories[name]
49
+ end
50
+
37
51
  # Access to all messages.
38
52
  # Use with caution in production as there are probably
39
53
  # a lot of messages so queries could take a long time or timeout.
@@ -0,0 +1,19 @@
1
+ module Messaging
2
+ module Adapters
3
+ class Test
4
+ class Categories
5
+ def initialize
6
+ clear!
7
+ end
8
+
9
+ def [](name)
10
+ @categories[name]
11
+ end
12
+
13
+ def clear!
14
+ @categories = Hash.new { |h, k| h[k] = Category.new(k) }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Messaging
2
+ module Adapters
3
+ class Test
4
+ class Category
5
+ attr_accessor :name
6
+
7
+ def initialize(name)
8
+ self.name = name
9
+ end
10
+
11
+ def messages
12
+ @messages ||= []
13
+ end
14
+
15
+ def delete_messages_older_than!(time)
16
+ messages.delete_if { |m| m.timestamp < time }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,4 +1,6 @@
1
1
  require_relative 'stream'
2
+ require_relative 'category'
3
+ require_relative 'categories'
2
4
 
3
5
  module Messaging
4
6
  module Adapters
@@ -29,7 +31,10 @@ module Messaging
29
31
  # @see Stream
30
32
  attr_reader :streams
31
33
 
34
+ attr_reader :categories
35
+
32
36
  def initialize
37
+ @categories = Categories.new
33
38
  clear!
34
39
  end
35
40
 
@@ -40,8 +45,13 @@ module Messaging
40
45
  streams[name]
41
46
  end
42
47
 
48
+ def category(name)
49
+ categories[name]
50
+ end
51
+
43
52
  def clear!
44
53
  @streams = Hash.new { |h, k| h[k] = Stream.new(k) }
54
+ categories.clear!
45
55
  @messages = []
46
56
  end
47
57
 
@@ -55,10 +65,12 @@ module Messaging
55
65
  return message unless message.stream_name
56
66
 
57
67
  stream = stream(message.stream_name)
68
+ category = category(message.stream_name.split('$').first)
58
69
  ExpectedVersion.new(message.expected_version || :any).match!(stream.current_position)
59
70
  persisted_message = message.class.new(message.attributes.merge(stream_position: stream.current_position + 1))
60
71
  @messages << persisted_message
61
72
  stream.messages << persisted_message
73
+ category.messages << persisted_message
62
74
  persisted_message
63
75
  end
64
76
  end
@@ -92,6 +92,18 @@ module Messaging
92
92
  nil
93
93
  end
94
94
 
95
+ def stream_category
96
+ return unless stream_name
97
+
98
+ stream_name.split('$').first
99
+ end
100
+
101
+ def stream_id
102
+ return unless stream_name
103
+
104
+ stream_name.split('$').last
105
+ end
106
+
95
107
  def message_type
96
108
  self.class.to_s
97
109
  end
@@ -1,3 +1,3 @@
1
1
  module Messaging
2
- VERSION = '3.4.2'.freeze
2
+ VERSION = '3.4.3'.freeze
3
3
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'activerecord'
22
22
  spec.add_dependency 'activesupport'
23
- spec.add_dependency 'bukowskis_after_transaction'
23
+ spec.add_dependency 'after_transaction'
24
24
  spec.add_dependency 'method_object'
25
25
  spec.add_dependency 'concurrent-ruby', '>= 1.0.2'
26
26
  spec.add_dependency 'concurrent-ruby-ext', '>= 1.0.2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.2
4
+ version: 3.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bukowskis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-14 00:00:00.000000000 Z
11
+ date: 2019-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bukowskis_after_transaction
42
+ name: after_transaction
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -275,7 +275,6 @@ files:
275
275
  - ".rspec"
276
276
  - ".ruby-version"
277
277
  - Gemfile
278
- - Gemfile.lock
279
278
  - README.md
280
279
  - Rakefile
281
280
  - _config.yml
@@ -289,11 +288,15 @@ files:
289
288
  - lib/messaging/adapters/kafka/producer.rb
290
289
  - lib/messaging/adapters/postgres.rb
291
290
  - lib/messaging/adapters/postgres/advisory_transaction_lock.rb
291
+ - lib/messaging/adapters/postgres/categories.rb
292
+ - lib/messaging/adapters/postgres/category.rb
292
293
  - lib/messaging/adapters/postgres/serialized_message.rb
293
294
  - lib/messaging/adapters/postgres/store.rb
294
295
  - lib/messaging/adapters/postgres/stream.rb
295
296
  - lib/messaging/adapters/postgres/streams.rb
296
297
  - lib/messaging/adapters/test.rb
298
+ - lib/messaging/adapters/test/categories.rb
299
+ - lib/messaging/adapters/test/category.rb
297
300
  - lib/messaging/adapters/test/consumer.rb
298
301
  - lib/messaging/adapters/test/store.rb
299
302
  - lib/messaging/adapters/test/stream.rb
@@ -1,222 +0,0 @@
1
- GIT
2
- remote: https://github.com/bukowskis/after_transaction.git
3
- revision: d9c250d497b861cdeb1aa924d82bbc5d38cfc56a
4
- specs:
5
- bukowskis_after_transaction (0.0.1)
6
- activerecord (< 6.0)
7
-
8
- GIT
9
- remote: https://github.com/bukowskis/method_object.git
10
- revision: bfb21cabafceec3b191d5c42d681a8e99ff38e6d
11
- specs:
12
- bukowskis_method_object (0.0.1)
13
- dry-initializer
14
-
15
- PATH
16
- remote: .
17
- specs:
18
- messaging (3.4.2)
19
- activerecord
20
- activesupport
21
- bukowskis_after_transaction
22
- concurrent-ruby (>= 1.0.2)
23
- concurrent-ruby-ext (>= 1.0.2)
24
- dry-configurable
25
- dry-container
26
- dry-equalizer
27
- dry-initializer
28
- meter (>= 1.2.1)
29
- method_object
30
- ruby-kafka (>= 0.5.3)
31
- virtus
32
-
33
- GEM
34
- remote: https://rubygems.org/
35
- specs:
36
- actionpack (5.2.2)
37
- actionview (= 5.2.2)
38
- activesupport (= 5.2.2)
39
- rack (~> 2.0)
40
- rack-test (>= 0.6.3)
41
- rails-dom-testing (~> 2.0)
42
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
43
- actionview (5.2.2)
44
- activesupport (= 5.2.2)
45
- builder (~> 3.1)
46
- erubi (~> 1.4)
47
- rails-dom-testing (~> 2.0)
48
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
49
- activemodel (5.2.2)
50
- activesupport (= 5.2.2)
51
- activerecord (5.2.2)
52
- activemodel (= 5.2.2)
53
- activesupport (= 5.2.2)
54
- arel (>= 9.0)
55
- activesupport (5.2.2)
56
- concurrent-ruby (~> 1.0, >= 1.0.2)
57
- i18n (>= 0.7, < 2)
58
- minitest (~> 5.1)
59
- tzinfo (~> 1.1)
60
- arel (9.0.0)
61
- axiom-types (0.1.1)
62
- descendants_tracker (~> 0.0.4)
63
- ice_nine (~> 0.11.0)
64
- thread_safe (~> 0.3, >= 0.3.1)
65
- bootsnap (1.3.2)
66
- msgpack (~> 1.0)
67
- builder (3.2.3)
68
- coderay (1.1.2)
69
- coercible (1.0.0)
70
- descendants_tracker (~> 0.0.1)
71
- concurrent-ruby (1.1.4)
72
- concurrent-ruby-ext (1.1.4)
73
- concurrent-ruby (= 1.1.4)
74
- connection_pool (2.2.2)
75
- crass (1.0.4)
76
- descendants_tracker (0.0.4)
77
- thread_safe (~> 0.3, >= 0.3.1)
78
- diff-lcs (1.3)
79
- digest-crc (0.4.1)
80
- docile (1.3.1)
81
- dry-configurable (0.8.3)
82
- concurrent-ruby (~> 1.0)
83
- dry-core (~> 0.4, >= 0.4.7)
84
- dry-container (0.7.2)
85
- concurrent-ruby (~> 1.0)
86
- dry-configurable (~> 0.1, >= 0.1.3)
87
- dry-core (0.4.9)
88
- concurrent-ruby (~> 1.0)
89
- dry-equalizer (0.2.2)
90
- dry-initializer (2.5.0)
91
- equalizer (0.0.11)
92
- erubi (1.8.0)
93
- ffi (1.10.0)
94
- geocoder (1.2.13)
95
- hashie (3.6.0)
96
- i18n (1.5.3)
97
- concurrent-ruby (~> 1.0)
98
- ice_nine (0.11.2)
99
- json (2.1.0)
100
- listen (3.1.5)
101
- rb-fsevent (~> 0.9, >= 0.9.4)
102
- rb-inotify (~> 0.9, >= 0.9.7)
103
- ruby_dep (~> 1.2)
104
- locality (1.1.0)
105
- activesupport
106
- geocoder (= 1.2.13)
107
- hashie
108
- i18n
109
- maxminddb (= 0.1.8)
110
- operation
111
- trouble
112
- loofah (2.2.3)
113
- crass (~> 1.0.2)
114
- nokogiri (>= 1.5.9)
115
- maxminddb (0.1.8)
116
- meter (1.2.7)
117
- locality (~> 1.1.0)
118
- useragent (~> 0.16.3)
119
- method_object (1.0.0)
120
- dry-initializer
121
- method_source (0.9.2)
122
- mini_portile2 (2.4.0)
123
- minitest (5.11.3)
124
- msgpack (1.2.6)
125
- nokogiri (1.10.1)
126
- mini_portile2 (~> 2.4.0)
127
- operation (1.4.1)
128
- pg (1.1.4)
129
- pry (0.12.2)
130
- coderay (~> 1.1.0)
131
- method_source (~> 0.9.0)
132
- pry-rails (0.3.9)
133
- pry (>= 0.10.4)
134
- rack (2.0.6)
135
- rack-protection (2.0.5)
136
- rack
137
- rack-test (1.1.0)
138
- rack (>= 1.0, < 3)
139
- rails-dom-testing (2.0.3)
140
- activesupport (>= 4.2.0)
141
- nokogiri (>= 1.6)
142
- rails-html-sanitizer (1.0.4)
143
- loofah (~> 2.2, >= 2.2.2)
144
- railties (5.2.2)
145
- actionpack (= 5.2.2)
146
- activesupport (= 5.2.2)
147
- method_source
148
- rake (>= 0.8.7)
149
- thor (>= 0.19.0, < 2.0)
150
- rake (10.5.0)
151
- rb-fsevent (0.10.3)
152
- rb-inotify (0.10.0)
153
- ffi (~> 1.0)
154
- redis (4.1.0)
155
- rspec (3.8.0)
156
- rspec-core (~> 3.8.0)
157
- rspec-expectations (~> 3.8.0)
158
- rspec-mocks (~> 3.8.0)
159
- rspec-core (3.8.0)
160
- rspec-support (~> 3.8.0)
161
- rspec-expectations (3.8.2)
162
- diff-lcs (>= 1.2.0, < 2.0)
163
- rspec-support (~> 3.8.0)
164
- rspec-mocks (3.8.0)
165
- diff-lcs (>= 1.2.0, < 2.0)
166
- rspec-support (~> 3.8.0)
167
- rspec-rails (3.8.2)
168
- actionpack (>= 3.0)
169
- activesupport (>= 3.0)
170
- railties (>= 3.0)
171
- rspec-core (~> 3.8.0)
172
- rspec-expectations (~> 3.8.0)
173
- rspec-mocks (~> 3.8.0)
174
- rspec-support (~> 3.8.0)
175
- rspec-support (3.8.0)
176
- ruby-kafka (0.7.10)
177
- digest-crc
178
- ruby_dep (1.5.0)
179
- sidekiq (5.2.5)
180
- connection_pool (~> 2.2, >= 2.2.2)
181
- rack (>= 1.5.0)
182
- rack-protection (>= 1.5.0)
183
- redis (>= 3.3.5, < 5)
184
- simplecov (0.16.1)
185
- docile (~> 1.1)
186
- json (>= 1.8, < 3)
187
- simplecov-html (~> 0.10.0)
188
- simplecov-html (0.10.2)
189
- thor (0.20.3)
190
- thread_safe (0.3.6)
191
- trouble (0.0.13)
192
- tzinfo (1.2.5)
193
- thread_safe (~> 0.1)
194
- useragent (0.16.10)
195
- virtus (1.0.5)
196
- axiom-types (~> 0.1)
197
- coercible (~> 1.0)
198
- descendants_tracker (~> 0.0, >= 0.0.3)
199
- equalizer (~> 0.0, >= 0.0.9)
200
-
201
- PLATFORMS
202
- ruby
203
-
204
- DEPENDENCIES
205
- bootsnap
206
- bukowskis_after_transaction!
207
- bukowskis_method_object!
208
- bundler (~> 1.14)
209
- listen
210
- messaging!
211
- pg
212
- pry
213
- pry-rails
214
- railties
215
- rake (~> 10.0)
216
- rspec (~> 3.0)
217
- rspec-rails
218
- sidekiq
219
- simplecov
220
-
221
- BUNDLED WITH
222
- 1.17.3