deimos-ruby 2.3.0 → 2.3.1
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/README.md +4 -0
- data/lib/deimos/active_record_consumer.rb +1 -0
- data/lib/deimos/active_record_producer.rb +11 -5
- data/lib/deimos/version.rb +1 -1
- data/spec/active_record_batch_consumer_association_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce1117d7a1d29304fcb0cafca935db90c4378ceaf9aa089dfcf9fa56fe5ea25d
|
|
4
|
+
data.tar.gz: 964f517ef411af2dcb3dbbc9f6e507d34fefcac6ef9321b8937d686bd3e307b7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5684bbf8cc1e2a0831369b47f28ffb84795a3d21a47b1b11d159b2909e9af36fd83b1756a47a9902d04c792a0a389cb8d675e0451f50e75c7d8c3ccf50a389ac
|
|
7
|
+
data.tar.gz: 9946b5a3ceeae405778731c82e1bfcc24dfae89a19bb0b2553620446815b712abc81a2bb9303e31ecb1d8d7aa68c3856df6cb2c46c1264f3305e6dbe0e3b530b
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## UNRELEASED
|
|
9
9
|
|
|
10
|
+
# 2.3.1 - 2026-01-22
|
|
11
|
+
|
|
12
|
+
- Feature: Allow strings to be used in the `record_class` declaration.
|
|
13
|
+
|
|
10
14
|
# 2.3.0 - 2026-01-13
|
|
11
15
|
|
|
12
16
|
- Feature: Support broker setting per topic in producer configs.
|
data/README.md
CHANGED
|
@@ -398,6 +398,8 @@ class MyProducer < Deimos::ActiveRecordProducer
|
|
|
398
398
|
# using the default functionality and don't need to override it)
|
|
399
399
|
# by setting `refetch` to false. This will avoid extra database fetches.
|
|
400
400
|
record_class Widget, refetch: false
|
|
401
|
+
|
|
402
|
+
# You can use a string here instead to avoid eager loading: record_class 'Widget'
|
|
401
403
|
|
|
402
404
|
# Optionally override this if you want the message to be
|
|
403
405
|
# sent even if fields that aren't in the schema are changed.
|
|
@@ -485,6 +487,7 @@ A sample consumer would look as follows:
|
|
|
485
487
|
```ruby
|
|
486
488
|
class MyConsumer < Deimos::ActiveRecordConsumer
|
|
487
489
|
record_class Widget
|
|
490
|
+
# or use a string: record_class 'Widget'
|
|
488
491
|
|
|
489
492
|
# Optional override of the way to fetch records based on payload and
|
|
490
493
|
# key. Default is to use the key to search the primary key of the table.
|
|
@@ -562,6 +565,7 @@ A sample batch consumer would look as follows:
|
|
|
562
565
|
```ruby
|
|
563
566
|
class MyConsumer < Deimos::ActiveRecordConsumer
|
|
564
567
|
record_class Widget
|
|
568
|
+
# or use a string: record_class 'Widget'
|
|
565
569
|
|
|
566
570
|
# Controls whether the batch is compacted before consuming.
|
|
567
571
|
# If true, only the last message for each unique key in a batch will be
|
|
@@ -13,18 +13,24 @@ module Deimos
|
|
|
13
13
|
class ActiveRecordProducer < Producer
|
|
14
14
|
class << self
|
|
15
15
|
# Indicate the class this producer is working on.
|
|
16
|
-
# @param klass [Class]
|
|
16
|
+
# @param klass [Class,String]
|
|
17
17
|
# @param refetch [Boolean] if true, and we are given a hash instead of
|
|
18
18
|
# a record object, refetch the record to pass into the `generate_payload`
|
|
19
19
|
# method.
|
|
20
20
|
# @return [void]
|
|
21
21
|
def record_class(klass=nil, refetch: true)
|
|
22
|
-
return
|
|
22
|
+
return record_klass if klass.nil?
|
|
23
23
|
|
|
24
24
|
@record_class = klass
|
|
25
25
|
@refetch_record = refetch
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
# @return [Class,nil]
|
|
29
|
+
def record_klass
|
|
30
|
+
@record_class = @record_class.constantize if @record_class.is_a?(String)
|
|
31
|
+
@record_class
|
|
32
|
+
end
|
|
33
|
+
|
|
28
34
|
# @param record [ActiveRecord::Base]
|
|
29
35
|
# @param force_send [Boolean]
|
|
30
36
|
# @return [void]
|
|
@@ -38,14 +44,14 @@ module Deimos
|
|
|
38
44
|
def send_events(records, force_send: false)
|
|
39
45
|
return if Deimos.producers_disabled?(self)
|
|
40
46
|
|
|
41
|
-
primary_key =
|
|
47
|
+
primary_key = record_klass&.primary_key
|
|
42
48
|
messages = records.map do |record|
|
|
43
49
|
if record.respond_to?(:attributes)
|
|
44
50
|
attrs = record.attributes.with_indifferent_access
|
|
45
51
|
else
|
|
46
52
|
attrs = record.with_indifferent_access
|
|
47
53
|
if @refetch_record && attrs[primary_key]
|
|
48
|
-
record =
|
|
54
|
+
record = record_klass.find(attrs[primary_key])
|
|
49
55
|
end
|
|
50
56
|
end
|
|
51
57
|
generate_payload(attrs, record).with_indifferent_access
|
|
@@ -96,7 +102,7 @@ module Deimos
|
|
|
96
102
|
# than this value).
|
|
97
103
|
# @return [ActiveRecord::Relation]
|
|
98
104
|
def poll_query(time_from:, time_to:, min_id:, column_name: :updated_at)
|
|
99
|
-
klass =
|
|
105
|
+
klass = record_klass
|
|
100
106
|
table = ActiveRecord::Base.connection.quote_table_name(klass.table_name)
|
|
101
107
|
column = ActiveRecord::Base.connection.quote_column_name(column_name)
|
|
102
108
|
primary = ActiveRecord::Base.connection.quote_column_name(klass.primary_key)
|
data/lib/deimos/version.rb
CHANGED
|
@@ -70,7 +70,7 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
|
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
before(:each) do
|
|
73
|
-
ActiveRecord::Base.connection.truncate_tables(
|
|
73
|
+
ActiveRecord::Base.connection.truncate_tables(:widgets, :details, :locales)
|
|
74
74
|
Widget.create!(test_id: 'bad_id', some_int: 100) # should not show up
|
|
75
75
|
end
|
|
76
76
|
|