deimos-ruby 1.22 → 1.22.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f8d5ac90c65bc034c6ddcd9992cdc2244100e0c6ac8f7091e253055094580ad
4
- data.tar.gz: 385c04f21fd913f4c913e851010c8a27915e6cb253643fc334b6a73497c0312f
3
+ metadata.gz: 5aa472d5bdd8c86fe0502451f7554598d189fa0d5004603d8970561feed38d9f
4
+ data.tar.gz: 669d564cb23fccc41a9b5a3dd37c49a17787adf7fcecd486746f9d91031d8367
5
5
  SHA512:
6
- metadata.gz: 33edfce1a07f88bd039cde29a33b63e59411b50237c8869ab06432e9d2622d8c2c506d7311d163adc4bc5ee05344ee379cb5c2e32d99661568446c77c93abf5e
7
- data.tar.gz: ed6f9cff6af0cd6e391c4f891e46874628cdbe41702d6114925417872231b2961d18b2239b83312f2f4fa45105a8d3d29282693252111eb0271a9e83ed2a98a6
6
+ metadata.gz: 3f49565845478349949d7dd5909b7d276590f91201d0848123c42a0b433114ce2a31cda8a0d43058f6f3f76114d3dfc1d32b8ee53a2a291588865ed5aaa8a8ec
7
+ data.tar.gz: 295802ba93bbf1e8a9c6ca95ac1944b85d3676881c3cb37854f883d42630f68f11a8971527611f1bf1c4681e5b8fab4aa202c1bcd2b1863296236b9a175bd253
data/CHANGELOG.md CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ # 1.22.2 - 2023-05-10
11
+ - Feature: Add `DEIMOS_TASK_NAME` env variable when running a task (consumer, DB poller, DB producer).
12
+
13
+ # 1.22.1 - 2023-05-01
14
+
15
+ - Fix: Bug introduced with 1.22 when associations are not used
16
+
10
17
  # 1.22 - 2023-05-01
11
18
 
12
19
  - Feature: Added `replace_associations` and changed default behavior for multi-table consuming. No longer relies on Rails direct associations and wonky magic for new vs. existing records.
@@ -183,9 +183,13 @@ module Deimos
183
183
  attrs = attrs.merge(record_key(m.key))
184
184
  next unless attrs
185
185
 
186
+ col = if @klass.column_names.include?(self.class.bulk_import_id_column.to_s)
187
+ self.class.bulk_import_id_column
188
+ end
189
+
186
190
  BatchRecord.new(klass: @klass,
187
191
  attributes: attrs,
188
- bulk_import_column: self.class.bulk_import_id_column)
192
+ bulk_import_column: col)
189
193
  end
190
194
  BatchRecordList.new(records.compact)
191
195
  end
@@ -26,7 +26,6 @@ module Deimos
26
26
  @klass = klass
27
27
  if bulk_import_column
28
28
  self.bulk_import_column = bulk_import_column
29
- validate_import_id!
30
29
  self.bulk_import_id = SecureRandom.uuid
31
30
  attributes[bulk_import_column] = bulk_import_id
32
31
  end
@@ -35,6 +34,7 @@ module Deimos
35
34
  assoc_keys = attributes.keys.select { |k| klass.reflect_on_association(k) }
36
35
  # a hash with just the association keys, removing all actual column information.
37
36
  self.associations = attributes.slice(*assoc_keys)
37
+ validate_import_id! if self.associations.any?
38
38
  end
39
39
 
40
40
  # Checks whether the entities has necessary columns for association saving to work
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.22'
4
+ VERSION = '1.22.2'
5
5
  end
@@ -12,6 +12,7 @@ namespace :deimos do
12
12
  config.producers.backend = :kafka if config.producers.backend == :kafka_async
13
13
  end
14
14
  ENV['DEIMOS_RAKE_TASK'] = 'true'
15
+ ENV['DEIMOS_TASK_NAME'] = 'consumer'
15
16
  STDOUT.sync = true
16
17
  Rails.logger.info('Running deimos:start rake task.')
17
18
  Phobos::CLI::Commands.start(%w(start --skip_config))
@@ -20,6 +21,7 @@ namespace :deimos do
20
21
  desc 'Starts the Deimos database producer'
21
22
  task db_producer: :environment do
22
23
  ENV['DEIMOS_RAKE_TASK'] = 'true'
24
+ ENV['DEIMOS_TASK_NAME'] = 'db_producer'
23
25
  STDOUT.sync = true
24
26
  Rails.logger.info('Running deimos:db_producer rake task.')
25
27
  thread_count = ENV['THREAD_COUNT'].to_i.zero? ? 1 : ENV['THREAD_COUNT'].to_i
@@ -28,6 +30,7 @@ namespace :deimos do
28
30
 
29
31
  task db_poller: :environment do
30
32
  ENV['DEIMOS_RAKE_TASK'] = 'true'
33
+ ENV['DEIMOS_TASK_NAME'] = 'db_poller'
31
34
  STDOUT.sync = true
32
35
  Rails.logger.info('Running deimos:db_poller rake task.')
33
36
  Deimos::Utils::DbPoller.start!
@@ -74,7 +74,9 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
74
74
  end
75
75
 
76
76
  prepend_before(:each) do
77
+ consumer_class.config[:bulk_import_id_column] = :bulk_import_id
77
78
  stub_const('MyBatchConsumer', consumer_class)
79
+ stub_const('ConsumerTest::MyBatchConsumer', consumer_class)
78
80
  end
79
81
 
80
82
  # Helper to publish a list of messages and call the consumer
@@ -157,7 +159,6 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
157
159
  end
158
160
 
159
161
  it 'should raise error when bulk_import_id is not found' do
160
- stub_const('MyBatchConsumer', consumer_class)
161
162
  expect {
162
163
  publish_batch([{ key: 2,
163
164
  payload: { test_id: 'xyz', some_int: 5, title: 'Widget Title' } }])
@@ -169,6 +170,7 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
169
170
  context 'with one-to-one relation in association and custom bulk_import_id' do
170
171
  before(:each) do
171
172
  consumer_class.config[:bulk_import_id_column] = :custom_id
173
+ consumer_class.config[:replace_associations] = false
172
174
  end
173
175
 
174
176
  before(:all) do
@@ -177,7 +179,6 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
177
179
  end
178
180
 
179
181
  it 'should save item to widget and associated detail' do
180
- stub_const('MyBatchConsumer', consumer_class)
181
182
  publish_batch([{ key: 2,
182
183
  payload: { test_id: 'xyz', some_int: 5, title: 'Widget Title' } }])
183
184
  expect(Widget.count).to eq(2)
@@ -188,7 +189,6 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
188
189
 
189
190
  context 'with one-to-many relationship in association and default bulk_import_id' do
190
191
  before(:each) do
191
- consumer_class.config[:bulk_import_id_column] = :bulk_import_id
192
192
  consumer_class.config[:replace_associations] = false
193
193
  consumer_class.record_attributes_proc = proc do |payload|
194
194
  {
@@ -209,7 +209,7 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
209
209
  end
210
210
 
211
211
  it 'should save item to widget and associated details' do
212
- stub_const('MyBatchConsumer', consumer_class)
212
+ consumer_class.config[:replace_associations] = false
213
213
  publish_batch([{ key: 2,
214
214
  payload: { test_id: 'xyz', some_int: 5, title: 'Widget Title' } }])
215
215
  expect(Widget.count).to eq(2)
@@ -229,7 +229,6 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
229
229
 
230
230
  context 'with replace_associations on' do
231
231
  before(:each) do
232
- consumer_class.config[:bulk_import_id_column] = :bulk_import_id
233
232
  consumer_class.config[:replace_associations] = true
234
233
  consumer_class.record_attributes_proc = proc do |payload|
235
234
  {
@@ -250,7 +249,6 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
250
249
  end
251
250
 
252
251
  it 'should save item to widget and replace associated details' do
253
- stub_const('MyBatchConsumer', consumer_class)
254
252
  publish_batch([{ key: 2,
255
253
  payload: { test_id: 'xyz', some_int: 5, title: 'Widget Title' } }])
256
254
  expect(Widget.count).to eq(2)
@@ -271,12 +269,10 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
271
269
 
272
270
  context 'with invalid models' do
273
271
  before(:each) do
274
- consumer_class.config[:bulk_import_id_column] = :bulk_import_id
275
272
  consumer_class.should_consume_proc = proc { |val| val.some_int <= 10 }
276
273
  end
277
274
 
278
275
  it 'should only save valid models' do
279
- stub_const('MyBatchConsumer', consumer_class)
280
276
  publish_batch([{ key: 2,
281
277
  payload: { test_id: 'xyz', some_int: 5, title: 'Widget Title' } },
282
278
  { key: 3,
@@ -32,6 +32,8 @@ module ActiveRecordBatchConsumerTest
32
32
 
33
33
  prepend_before(:each) do
34
34
  stub_const('MyBatchConsumer', consumer_class)
35
+ stub_const('ConsumerTest::MyBatchConsumer', consumer_class)
36
+ consumer_class.config[:bulk_import_id_column] = :bulk_import_id # default
35
37
  end
36
38
 
37
39
  around(:each) do |ex|
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.22'
4
+ version: 1.22.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-05-01 00:00:00.000000000 Z
11
+ date: 2023-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro_turf