deimos-ruby 2.3.1 → 2.3.2
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 +5 -0
- data/deimos-ruby.gemspec +1 -0
- data/lib/deimos/active_record_consume/batch_consumption.rb +19 -1
- data/lib/deimos/version.rb +1 -1
- data/spec/active_record_batch_consumer_spec.rb +85 -0
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 11656e5d925198470fb1c6918808e2dda7b769d98397e9b0f973316a21fe1616
|
|
4
|
+
data.tar.gz: 4f34eae61a408809aaa6c0d70d0fe535c27ea300e479612c8273bd63cf553b62
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 60c5d0fe69d3787c972c647d907de9159c4f33a63c8f1e3913c9816bd18e056f24721549377bf3ebdc25578c800c62ad7ab2f5a056e0562cacd1026858ea5d2f
|
|
7
|
+
data.tar.gz: 252a59f9db351029fd2cd67c679bddd50a854e4797855a8c7b5e7248e6b0ab71aad041d7b7e3dd900eb5c90c6cc5f82301461f58a749fe997f99d8f65d8b3f3e
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## UNRELEASED
|
|
9
9
|
|
|
10
|
+
# 2.3.2 - 2026-02-20
|
|
11
|
+
|
|
12
|
+
- Feature: Add overridable process_message? for batch consumption.
|
|
13
|
+
- Feature: Add overridable post_process_batch for batch consumption.
|
|
14
|
+
|
|
10
15
|
# 2.3.1 - 2026-01-22
|
|
11
16
|
|
|
12
17
|
- Feature: Allow strings to be used in the `record_class` declaration.
|
data/deimos-ruby.gemspec
CHANGED
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
|
|
|
34
34
|
spec.add_development_dependency('karafka-testing', '~> 2.0')
|
|
35
35
|
spec.add_development_dependency('pg', '~> 1.1')
|
|
36
36
|
spec.add_development_dependency('proto_turf')
|
|
37
|
+
spec.add_development_dependency('pry', '~> 0.14.1')
|
|
37
38
|
spec.add_development_dependency('rails', '~> 8.0')
|
|
38
39
|
spec.add_development_dependency('rake', '~> 13')
|
|
39
40
|
spec.add_development_dependency('rspec', '~> 3')
|
|
@@ -25,7 +25,15 @@ module Deimos
|
|
|
25
25
|
# they are split
|
|
26
26
|
# @return [void]
|
|
27
27
|
def consume_batch
|
|
28
|
-
|
|
28
|
+
filtered = messages.select { |p| process_message?(p.payload) }
|
|
29
|
+
skipped_count = messages.size - filtered.size
|
|
30
|
+
if skipped_count.positive?
|
|
31
|
+
Deimos::Logging.log_debug(
|
|
32
|
+
message: 'Skipping processing of messages in batch',
|
|
33
|
+
skipped_count: skipped_count
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
deimos_messages = filtered.map { |p| Deimos::Message.new(p.payload, key: p.key) }
|
|
29
37
|
|
|
30
38
|
tag = topic.name
|
|
31
39
|
Deimos.config.tracer.active_span.set_tag('topic', tag)
|
|
@@ -37,6 +45,8 @@ module Deimos
|
|
|
37
45
|
uncompacted_update(deimos_messages)
|
|
38
46
|
end
|
|
39
47
|
end
|
|
48
|
+
|
|
49
|
+
post_process_batch(deimos_messages)
|
|
40
50
|
end
|
|
41
51
|
|
|
42
52
|
protected
|
|
@@ -94,6 +104,14 @@ module Deimos
|
|
|
94
104
|
true
|
|
95
105
|
end
|
|
96
106
|
|
|
107
|
+
# Perform any post-processing after a batch has been consumed.
|
|
108
|
+
# Called once per batch with the list of Deimos::Message that were processed (after filtering and compaction).
|
|
109
|
+
# @param messages [Array<Deimos::Message>] The batch of messages that were processed
|
|
110
|
+
# @return [void]
|
|
111
|
+
def post_process_batch(_messages)
|
|
112
|
+
nil
|
|
113
|
+
end
|
|
114
|
+
|
|
97
115
|
private
|
|
98
116
|
|
|
99
117
|
# Compact a batch of messages, taking only the last message for each
|
data/lib/deimos/version.rb
CHANGED
|
@@ -57,6 +57,12 @@ module ActiveRecordBatchConsumerTest
|
|
|
57
57
|
Class.new(described_class) do
|
|
58
58
|
record_class Widget
|
|
59
59
|
compacted false
|
|
60
|
+
|
|
61
|
+
def process_message?(payload)
|
|
62
|
+
return true if payload.nil?
|
|
63
|
+
|
|
64
|
+
payload['test_id'] != 'skipme'
|
|
65
|
+
end
|
|
60
66
|
end
|
|
61
67
|
end
|
|
62
68
|
|
|
@@ -103,6 +109,27 @@ module ActiveRecordBatchConsumerTest
|
|
|
103
109
|
)
|
|
104
110
|
end
|
|
105
111
|
|
|
112
|
+
it 'should not create records for messages that return false from process_message?' do
|
|
113
|
+
publish_batch(
|
|
114
|
+
[
|
|
115
|
+
{ key: 1,
|
|
116
|
+
payload: { test_id: 'abc', some_int: 3 } },
|
|
117
|
+
{ key: 2,
|
|
118
|
+
payload: { test_id: 'skipme', some_int: 4 } },
|
|
119
|
+
{ key: 3,
|
|
120
|
+
payload: { test_id: 'ghi', some_int: 5 } }
|
|
121
|
+
]
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
expect(all_widgets).
|
|
125
|
+
to contain_exactly(
|
|
126
|
+
have_attributes(id: 1, test_id: 'abc', some_int: 3, updated_at: start,
|
|
127
|
+
created_at: start),
|
|
128
|
+
have_attributes(id: 3, test_id: 'ghi', some_int: 5, updated_at: start,
|
|
129
|
+
created_at: start)
|
|
130
|
+
)
|
|
131
|
+
end
|
|
132
|
+
|
|
106
133
|
it 'should handle deleting a record that doesn\'t exist' do
|
|
107
134
|
publish_batch(
|
|
108
135
|
[
|
|
@@ -805,6 +832,64 @@ module ActiveRecordBatchConsumerTest
|
|
|
805
832
|
|
|
806
833
|
end
|
|
807
834
|
|
|
835
|
+
describe 'post_process_batch' do
|
|
836
|
+
before(:each) do
|
|
837
|
+
register_consumer(consumer_class,
|
|
838
|
+
'MySchema',
|
|
839
|
+
key_config: { plain: true })
|
|
840
|
+
MyBatchConsumer.last_post_process_batch = nil
|
|
841
|
+
end
|
|
842
|
+
|
|
843
|
+
let(:consumer_class) do
|
|
844
|
+
Class.new(described_class) do
|
|
845
|
+
class << self
|
|
846
|
+
attr_accessor :last_post_process_batch
|
|
847
|
+
end
|
|
848
|
+
|
|
849
|
+
record_class Widget
|
|
850
|
+
compacted false
|
|
851
|
+
|
|
852
|
+
def post_process_batch(messages)
|
|
853
|
+
self.class.last_post_process_batch = messages
|
|
854
|
+
end
|
|
855
|
+
|
|
856
|
+
def process_message?(payload)
|
|
857
|
+
payload['test_id'] != 'skipme'
|
|
858
|
+
end
|
|
859
|
+
end
|
|
860
|
+
end
|
|
861
|
+
|
|
862
|
+
it 'is called after the batch is processed with the processed messages' do
|
|
863
|
+
publish_batch(
|
|
864
|
+
[
|
|
865
|
+
{ key: 1,
|
|
866
|
+
payload: { test_id: 'abc', some_int: 3 } },
|
|
867
|
+
{ key: 2,
|
|
868
|
+
payload: { test_id: 'def', some_int: 4 } }
|
|
869
|
+
]
|
|
870
|
+
)
|
|
871
|
+
expect(MyBatchConsumer.last_post_process_batch.map(&:payload).map do |p|
|
|
872
|
+
p[:test_id]
|
|
873
|
+
end).to contain_exactly('abc', 'def')
|
|
874
|
+
end
|
|
875
|
+
|
|
876
|
+
it 'is called with filtered messages when process_message? excludes some' do
|
|
877
|
+
publish_batch(
|
|
878
|
+
[
|
|
879
|
+
{ key: 1,
|
|
880
|
+
payload: { test_id: 'abc', some_int: 3 } },
|
|
881
|
+
{ key: 2,
|
|
882
|
+
payload: { test_id: 'skipme', some_int: 4 } },
|
|
883
|
+
{ key: 3,
|
|
884
|
+
payload: { test_id: 'ghi', some_int: 5 } }
|
|
885
|
+
]
|
|
886
|
+
)
|
|
887
|
+
|
|
888
|
+
expect(MyBatchConsumer.last_post_process_batch.size).to eq(2)
|
|
889
|
+
expect(MyBatchConsumer.last_post_process_batch.map(&:key).map(&:to_i)).to contain_exactly(1, 3)
|
|
890
|
+
end
|
|
891
|
+
end
|
|
892
|
+
|
|
808
893
|
end
|
|
809
894
|
end
|
|
810
895
|
# rubocop:enable Lint/ConstantDefinitionInBlock
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: deimos-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.3.
|
|
4
|
+
version: 2.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Orner
|
|
@@ -245,6 +245,20 @@ dependencies:
|
|
|
245
245
|
- - ">="
|
|
246
246
|
- !ruby/object:Gem::Version
|
|
247
247
|
version: '0'
|
|
248
|
+
- !ruby/object:Gem::Dependency
|
|
249
|
+
name: pry
|
|
250
|
+
requirement: !ruby/object:Gem::Requirement
|
|
251
|
+
requirements:
|
|
252
|
+
- - "~>"
|
|
253
|
+
- !ruby/object:Gem::Version
|
|
254
|
+
version: 0.14.1
|
|
255
|
+
type: :development
|
|
256
|
+
prerelease: false
|
|
257
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
258
|
+
requirements:
|
|
259
|
+
- - "~>"
|
|
260
|
+
- !ruby/object:Gem::Version
|
|
261
|
+
version: 0.14.1
|
|
248
262
|
- !ruby/object:Gem::Dependency
|
|
249
263
|
name: rails
|
|
250
264
|
requirement: !ruby/object:Gem::Requirement
|