deimos-ruby 1.19.1.pre.beta1 → 1.19.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +2 -2
- data/docs/CONFIGURATION.md +0 -1
- data/lib/deimos/active_record_consume/batch_consumption.rb +4 -17
- data/lib/deimos/active_record_consumer.rb +0 -7
- data/lib/deimos/config/configuration.rb +0 -3
- data/lib/deimos/version.rb +1 -1
- data/lib/generators/deimos/bulk_import_id_generator.rb +0 -2
- data/spec/active_record_batch_consumer_mysql_spec.rb +1 -1
- data/spec/config/configuration_spec.rb +3 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34ab9629daca099d1745e192f379cdd5289c081fc241d2920966485c896611c1
|
4
|
+
data.tar.gz: 9dd093633667f4560312c0cd945083fb605d29cb4074d7807ea5a98c1a54d68a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02276cba6707533b241b0ea2b0f3c8bf74ebf8120515b7ca883a080f4bdd80a1e15e3120097d3b0627a6519b4dc4ccdf5fc4f4e2950111ae69c12a262ec5ac9b
|
7
|
+
data.tar.gz: 4a6236f8d659c90ef864a3b99b04518c5f045235079f7168540b4d25f862ac2554d228c9ea94d10f93dd1ead0c1edd8476a66c6b360cbb572ccdaf9740212dfa
|
data/CHANGELOG.md
CHANGED
@@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## UNRELEASED
|
9
9
|
|
10
|
-
|
10
|
+
# 1.19.2 - 2023-03-20
|
11
|
+
|
12
|
+
- Fix for saving associations where the primary key is not `id`.
|
13
|
+
|
14
|
+
# 1.19.1 - 2023-03-17
|
15
|
+
|
16
|
+
- Fix for `rails g deimos:bulk_import_id` generator.
|
11
17
|
|
12
18
|
# 1.19.0 - 2023-02-21
|
13
19
|
|
data/README.md
CHANGED
@@ -360,7 +360,7 @@ end
|
|
360
360
|
Sometimes, the Kafka message needs to be saved to multiple database tables. For example, if a `User` topic provides you metadata and profile image for users, we might want to save it to multiple tables: `User` and `Image`.
|
361
361
|
|
362
362
|
- The `association_list` configuration allows you to achieve this use case.
|
363
|
-
- The
|
363
|
+
- The `bulk_import_id_column` config allows you to specify column_name on `record_class` which can be used to retrieve IDs after save. Defaults to `bulk_import_id`. This config is *required* if you have associations but optional if you do not.
|
364
364
|
|
365
365
|
You must override the `build_records` and `bulk_import_columns` methods on your ActiveRecord class for this feature to work.
|
366
366
|
- `build_records` - This method is required to set the value of the `bulk_import_id` column and map Kafka messages to ActiveRecord model objects.
|
@@ -374,7 +374,7 @@ class MyBatchConsumer < Deimos::ActiveRecordConsumer
|
|
374
374
|
|
375
375
|
def build_records(messages)
|
376
376
|
# Initialise bulk_import_id and build ActiveRecord objects out of Kafka message attributes
|
377
|
-
messages.
|
377
|
+
messages.map do |m|
|
378
378
|
u = User.new(first_name: m.first_name, bulk_import_id: SecureRandom.uuid)
|
379
379
|
i = Image.new(attr1: m.image_url)
|
380
380
|
u.images << i
|
data/docs/CONFIGURATION.md
CHANGED
@@ -83,7 +83,6 @@ key_config|nil|Configuration hash for message keys. See [Kafka Message Keys](../
|
|
83
83
|
disabled|false|Set to true to skip starting an actual listener for this consumer on startup.
|
84
84
|
group_id|nil|ID of the consumer group.
|
85
85
|
use_schema_classes|nil|Set to true or false to enable or disable using the consumers schema classes. See [Generated Schema Classes](../README.md#generated-schema-classes)
|
86
|
-
max_db_batch_size|nil|Maximum limit for batching database calls to reduce the load on the db.
|
87
86
|
max_concurrency|1|Number of threads created for this listener. Each thread will behave as an independent consumer. They don't share any state.
|
88
87
|
start_from_beginning|true|Once the consumer group has checkpointed its progress in the topic's partitions, the consumers will always start from the checkpointed offsets, regardless of config. As such, this setting only applies when the consumer initially starts consuming from a topic
|
89
88
|
max_bytes_per_partition|512.kilobytes|Maximum amount of data fetched from a single partition at a time.
|
@@ -78,21 +78,8 @@ module Deimos
|
|
78
78
|
# deleted record (no payload)
|
79
79
|
removed, upserted = messages.partition(&:tombstone?)
|
80
80
|
|
81
|
-
if upserted.any?
|
82
|
-
|
83
|
-
upserted.each_slice(@max_db_batch_size) { |group| upsert_records(group) }
|
84
|
-
else
|
85
|
-
upsert_records(upserted)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
return unless removed.any?
|
90
|
-
|
91
|
-
if @max_db_batch_size
|
92
|
-
removed.each_slice(@max_db_batch_size) { |group| remove_records(group) }
|
93
|
-
else
|
94
|
-
remove_records(removed)
|
95
|
-
end
|
81
|
+
upsert_records(upserted) if upserted.any?
|
82
|
+
remove_records(removed) if removed.any?
|
96
83
|
end
|
97
84
|
|
98
85
|
# Upsert any non-deleted records
|
@@ -150,7 +137,7 @@ module Deimos
|
|
150
137
|
# Get associated `has_one` or `has_many` records for each entity
|
151
138
|
sub_records = Array(entity.send(assoc.name))
|
152
139
|
# Set IDS from master to each of the records in `has_one` or `has_many` relation
|
153
|
-
sub_records.each { |d| d.send("#{assoc.
|
140
|
+
sub_records.each { |d| d.send("#{assoc.foreign_key}=", entity.send(assoc.active_record_primary_key)) }
|
154
141
|
sub_records
|
155
142
|
}.flatten
|
156
143
|
|
@@ -256,7 +243,7 @@ module Deimos
|
|
256
243
|
return if entities.first.respond_to?(@bulk_import_id_column)
|
257
244
|
|
258
245
|
raise "Create bulk_import_id on #{entities.first.class} and set it in `build_records` for associations." \
|
259
|
-
' Run rails g deimos:bulk_import_id
|
246
|
+
' Run rails g deimos:bulk_import_id {table} to create the migration.'
|
260
247
|
end
|
261
248
|
|
262
249
|
# Fills Primary Key ID on in-memory objects.
|
@@ -48,12 +48,6 @@ module Deimos
|
|
48
48
|
def compacted(val)
|
49
49
|
config[:compacted] = val
|
50
50
|
end
|
51
|
-
|
52
|
-
# @param limit [Integer] Maximum number of transactions in a single database call.
|
53
|
-
# @return [void]
|
54
|
-
def max_db_batch_size(limit)
|
55
|
-
config[:max_db_batch_size] = limit
|
56
|
-
end
|
57
51
|
end
|
58
52
|
|
59
53
|
# Setup
|
@@ -68,7 +62,6 @@ module Deimos
|
|
68
62
|
end
|
69
63
|
|
70
64
|
@compacted = self.class.config[:compacted] != false
|
71
|
-
@max_db_batch_size = self.class.config[:max_db_batch_size]
|
72
65
|
end
|
73
66
|
|
74
67
|
# Override this method (with `super`) if you want to add/change the default
|
@@ -424,9 +424,6 @@ module Deimos
|
|
424
424
|
# Configure the usage of generated schema classes for this consumer
|
425
425
|
# @return [Boolean]
|
426
426
|
setting :use_schema_classes
|
427
|
-
# Optional maximum limit for batching database calls to reduce the load on the db.
|
428
|
-
# @return [Integer]
|
429
|
-
setting :max_db_batch_size
|
430
427
|
|
431
428
|
# These are the phobos "listener" configs. See CONFIGURATION.md for more
|
432
429
|
# info.
|
data/lib/deimos/version.rb
CHANGED
@@ -12,8 +12,6 @@ module Deimos
|
|
12
12
|
include Rails::Generators::Migration
|
13
13
|
include ActiveRecord::Generators::Migration
|
14
14
|
|
15
|
-
namespace 'deimos:bulk_import_id:setup'
|
16
|
-
|
17
15
|
argument :table_name, desc: 'The table to add bulk import column.', required: true
|
18
16
|
argument :column_name, desc: 'The bulk import ID column name.', default: 'bulk_import_id'
|
19
17
|
|
@@ -108,7 +108,7 @@ module ActiveRecordBatchConsumerTest
|
|
108
108
|
publish_batch([{ key: 2,
|
109
109
|
payload: { test_id: 'xyz', some_int: 5, title: 'Widget Title' } }])
|
110
110
|
}.to raise_error('Create bulk_import_id on ActiveRecordBatchConsumerTest::Widget'\
|
111
|
-
' and set it in `build_records` for associations. Run rails g deimos:bulk_import_id
|
111
|
+
' and set it in `build_records` for associations. Run rails g deimos:bulk_import_id {table}'\
|
112
112
|
' to create the migration.')
|
113
113
|
end
|
114
114
|
end
|
@@ -90,8 +90,7 @@ describe Deimos, 'configuration' do
|
|
90
90
|
offset_retention_time: nil,
|
91
91
|
heartbeat_interval: 10,
|
92
92
|
handler: 'ConsumerTest::MyConsumer',
|
93
|
-
use_schema_classes: nil
|
94
|
-
max_db_batch_size: nil
|
93
|
+
use_schema_classes: nil
|
95
94
|
}, {
|
96
95
|
topic: 'my_batch_consume_topic',
|
97
96
|
group_id: 'my_batch_group_id',
|
@@ -108,8 +107,7 @@ describe Deimos, 'configuration' do
|
|
108
107
|
offset_retention_time: nil,
|
109
108
|
heartbeat_interval: 10,
|
110
109
|
handler: 'ConsumerTest::MyBatchConsumer',
|
111
|
-
use_schema_classes: nil
|
112
|
-
max_db_batch_size: nil
|
110
|
+
use_schema_classes: nil
|
113
111
|
}
|
114
112
|
],
|
115
113
|
producer: {
|
@@ -260,8 +258,7 @@ describe Deimos, 'configuration' do
|
|
260
258
|
offset_retention_time: 13,
|
261
259
|
heartbeat_interval: 13,
|
262
260
|
handler: 'MyConfigConsumer',
|
263
|
-
use_schema_classes: false
|
264
|
-
max_db_batch_size: nil
|
261
|
+
use_schema_classes: false
|
265
262
|
}
|
266
263
|
],
|
267
264
|
producer: {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deimos-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.19.
|
4
|
+
version: 1.19.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Orner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro_turf
|
@@ -624,9 +624,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
624
624
|
version: '0'
|
625
625
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
626
626
|
requirements:
|
627
|
-
- - "
|
627
|
+
- - ">="
|
628
628
|
- !ruby/object:Gem::Version
|
629
|
-
version:
|
629
|
+
version: '0'
|
630
630
|
requirements: []
|
631
631
|
rubygems_version: 3.3.20
|
632
632
|
signing_key:
|