deimos-ruby 2.0.0.pre.alpha2 → 2.0.0.pre.alpha4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7563872db1d29eb0e6873eec799fe173ceb7484ec8e728063e49cacd3dc3083
4
- data.tar.gz: d768d9026137b265887c3e0a063c9737974338de2a460c2c747440ba6d2ea94c
3
+ metadata.gz: 13ff4c1182fe82aa5e41b6981480e463588c64803b060d1ea68aeeded001b945
4
+ data.tar.gz: 3cd1ff2eac1aa981aeef0c15d399850ffbfb13a71a3315476f62494eaea16f09
5
5
  SHA512:
6
- metadata.gz: 76c9cb88a3e130eedcdaa45e4ad5cdf9cbed0bdf3c61e68bde81358785f250429ad1c1ffbaaaa520e739f0e0ef3c16fd8a0f5422e706c3178267600456bf9930
7
- data.tar.gz: b0a531fdbd9b1ec9276f44783418e8df5fc358c6c3c2e1e51f6265b6e664cdf4fb83ad33d631f2a3ebb465aba52724d8941a7e97fbf49632f9299bd9249d7928
6
+ metadata.gz: '0389849fa59d727f6b44d850874e4b6a694e856b9dbfa1624282b77f6113ae31a208f3f41dae677b4563add662b7232462575059b05867298fd40440255d5e3d'
7
+ data.tar.gz: f03cd3234d22da82ae55976478023b90353823cceea9440aa805cc8994a527867ca1af074c6df2eb99a96f9a0efaa14a8da5bd10a00f5d0bf01c0bf746687333
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in boilerplate.gemspec
6
6
  gemspec
7
+ gem 'karafka', git: 'https://github.com/dorner/karafka', branch: 'redraw'
@@ -86,21 +86,22 @@ Deimos.configure do
86
86
  end
87
87
  ```
88
88
 
89
- | Config name | Default | Description |
90
- |--------------------------|---------------|---------------------------------------------------------------------------------------------------------------------------------------|
91
- | producer_class | nil | ActiveRecordProducer class to use for sending messages. |
92
- | mode | :time_based | Whether to use time-based polling or state-based polling. |
93
- | run_every | 60 | Amount of time in seconds to wait between runs. |
89
+ | Config name | Default | Description |
90
+ |--------------------------|--------------|---------------------------------------------------------------------------------------------------------------------------------------|
91
+ | producer_class | nil | ActiveRecordProducer class to use for sending messages. |
92
+ | producer_classes | [] | Array of ActiveRecordProducer classes to use for sending messages. You can use this instead of `producer_class`. |
93
+ | mode | :time_based | Whether to use time-based polling or state-based polling. |
94
+ | run_every | 60 | Amount of time in seconds to wait between runs. |
94
95
  | timestamp_column | `:updated_at` | Name of the column to query. Remember to add an index to this column! |
95
- | delay_time | 2 | Amount of time in seconds to wait before picking up records, to allow for transactions to finish. |
96
- | retries | 1 | The number of times to retry for a *non-Kafka* error. |
97
- | full_table | false | If set to true, do a full table dump to Kafka each run. Good for very small tables. Time-based only. |
98
- | start_from_beginning | true | If false, start from the current time instead of the beginning of time if this is the first time running the poller. Time-based only. |
99
- | state_column | nil | If set, this represents the DB column to use to update publishing status. State-based only. |
100
- | publish_timestamp_column | nil | If set, this represents the DB column to use to update when publishing is done. State-based only. |
101
- | published_state | nil | If set, the poller will update the `state_column` to this value when publishing succeeds. State-based only. |
102
- | failed_state | nil | If set, the poller will update the `state_column` to this value when publishing fails. State-based only. |
103
- | poller_class | nil | Poller subclass name to use for publishing to multiple kafka topics from a single poller. |
96
+ | delay_time | 2 | Amount of time in seconds to wait before picking up records, to allow for transactions to finish. |
97
+ | retries | 1 | The number of times to retry for a *non-Kafka* error. |
98
+ | full_table | false | If set to true, do a full table dump to Kafka each run. Good for very small tables. Time-based only. |
99
+ | start_from_beginning | true | If false, start from the current time instead of the beginning of time if this is the first time running the poller. Time-based only. |
100
+ | state_column | nil | If set, this represents the DB column to use to update publishing status. State-based only. |
101
+ | publish_timestamp_column | nil | If set, this represents the DB column to use to update when publishing is done. State-based only. |
102
+ | published_state | nil | If set, the poller will update the `state_column` to this value when publishing succeeds. State-based only. |
103
+ | failed_state | nil | If set, the poller will update the `state_column` to this value when publishing fails. State-based only. |
104
+ | poller_class | nil | Poller subclass name to use for publishing to multiple kafka topics from a single poller. |
104
105
 
105
106
  ## Karafka Routing
106
107
 
data/docs/UPGRADING.md CHANGED
@@ -216,6 +216,7 @@ The following events have been **renamed**:
216
216
 
217
217
  ### Additional breaking changes
218
218
  * `key_config` now defaults to `{none: true}` instead of erroring out if not set.
219
+ * `reraise_errors` now defaults to true if the Rails env is set to `test`, and false otherwise.
219
220
  * `fatal_error?` now receives a Karafka `messages` object instead of a payload hash or array of hashes.
220
221
  * `watched_attributes` has been moved from the corresponding ActiveRecord class to the ActiveRecordProducer class. The object being watched is passed into the method.
221
222
  * Removed `TestHelpers.full_integration_test!` and `kafka_test!` as Karafka does not currently support these use cases. If we need them back, we will need to put in changes to the testing library to support them.
@@ -53,7 +53,7 @@ module Deimos
53
53
  end
54
54
 
55
55
  def config
56
- Deimos.karafka_configs.find { |t| t.producer_class == self }
56
+ Deimos.karafka_configs.find { |t| t.producer_classes.include?(self) }
57
57
  end
58
58
 
59
59
  def encoder
@@ -19,10 +19,11 @@ module Deimos
19
19
  bulk_import_id_column: :bulk_import_id,
20
20
  replace_associations: true,
21
21
  each_message: false,
22
+ reraise_errors: Rails.env.test?,
22
23
  bulk_import_id_generator: proc { SecureRandom.uuid },
23
24
  fatal_error: proc { false }
24
25
  )
25
- if args.any?
26
+ if args.size.positive?
26
27
  @deimos_config.public_send("#{field}=", args[0])
27
28
  end
28
29
  @deimos_config[field]
@@ -1,18 +1,26 @@
1
1
  module Deimos
2
2
  class ProducerRoute < Karafka::Routing::Features::Base
3
- FIELDS = %i(producer_class payload_log disabled)
3
+ FIELDS = %i(producer_classes payload_log disabled)
4
4
 
5
- Config = Struct.new(*FIELDS, keyword_init: true)
5
+ Config = Struct.new(*FIELDS, keyword_init: true) do
6
+ def producer_class=(val)
7
+ self.producer_classes = [val]
8
+ end
9
+
10
+ def producer_class
11
+ self.producer_classes.first
12
+ end
13
+ end
6
14
  module Topic
7
- FIELDS.each do |field|
15
+ (FIELDS + [:producer_class]).each do |field|
8
16
  define_method(field) do |*args|
9
- active(false) if field == :producer_class
17
+ active(false) if %i(producer_class producer_classes).include?(field)
10
18
  @deimos_producer_config ||= Config.new
11
19
  if args.any?
12
20
  @deimos_producer_config.public_send("#{field}=", args[0])
13
21
  _deimos_setup_transcoders if schema && namespace
14
22
  end
15
- @deimos_producer_config[field]
23
+ @deimos_producer_config.send(field)
16
24
  end
17
25
  end
18
26
  end
@@ -3,7 +3,11 @@ module Deimos
3
3
  class << self
4
4
 
5
5
  def log_add(method, msg)
6
- Karafka.logger.tagged('Deimos') do |logger|
6
+ if Karafka.logger.respond_to?(:tagged)
7
+ Karafka.logger.tagged('Deimos') do |logger|
8
+ logger.send(method, msg.to_json)
9
+ end
10
+ else
7
11
  logger.send(method, msg.to_json)
8
12
  end
9
13
 
@@ -122,7 +122,7 @@ module Deimos
122
122
  end
123
123
 
124
124
  def karafka_config
125
- Deimos.karafka_configs.find { |topic| topic.producer_class == self }
125
+ Deimos.karafka_configs.find { |topic| topic.producer_classes.include?(self) }
126
126
  end
127
127
 
128
128
  def topic
@@ -98,6 +98,8 @@ module Deimos
98
98
  message_key = Deimos::TestHelpers.normalize_message(key)
99
99
  hash_matcher = RSpec::Matchers::BuiltIn::Match.new(message)
100
100
  Deimos::TestHelpers.sent_messages.any? do |m|
101
+ message.delete(:payload_key) if message.respond_to?(:[]) && message[:payload_key].nil?
102
+ m[:payload].delete(:payload_key) if m.respond_to?(:[]) && m[:payload]&.respond_to?(:[]) && m[:payload][:payload_key].nil?
101
103
  hash_matcher.send(:match, message, m[:payload]) &&
102
104
  topic == m[:topic] &&
103
105
  (key.present? ? message_key == m[:key] : true) &&
@@ -171,6 +173,7 @@ module Deimos
171
173
  unless call_original.nil?
172
174
  puts "test_consume_batch(call_original: true) is deprecated and will be removed in the future. You can remove the call_original parameter."
173
175
  end
176
+ karafka.consumer_messages.clear
174
177
  consumer = nil
175
178
  topic_name = nil
176
179
  if handler_class_or_topic.is_a?(String)
@@ -183,15 +186,22 @@ module Deimos
183
186
 
184
187
  Deimos.karafka_config_for(topic: topic_name).each_message(single)
185
188
 
186
- payloads.each_with_index do |payload, i|
187
- karafka.produce(payload, {key: keys[i], partition_key: partition_keys[i], topic: consumer.topic.name})
188
- end
189
- if block_given?
190
- allow_any_instance_of(consumer_class).to receive(:consume_batch) do
191
- yield
192
- end
189
+ # don't record messages sent with test_consume_batch
190
+ original_messages = karafka.produced_messages.dup
191
+ payloads.each_with_index do |payload, i|
192
+ karafka.produce(payload, {key: keys[i], partition_key: partition_keys[i], topic: consumer.topic.name})
193
+ end
194
+ if block_given?
195
+ allow_any_instance_of(consumer_class).to receive(:consume_batch) do
196
+ yield
193
197
  end
194
- consumer.consume
195
198
  end
199
+
200
+ # sent_messages should only include messages sent by application code, not this method
201
+ karafka.produced_messages.clear
202
+ karafka.produced_messages.concat(original_messages)
203
+
204
+ consumer.consume
205
+ end
196
206
  end
197
207
  end
@@ -38,9 +38,11 @@ module Deimos
38
38
  return nil if key.nil? || self.key_field.nil?
39
39
 
40
40
  decoded_key = self.backend.decode_key(key, self.key_field)
41
- return decoded_key unless @use_schema_classes
41
+ return decoded_key if self.key_field || !@use_schema_classes
42
42
 
43
- Utils::SchemaClass.instance(decoded_key,
43
+ schema_key = decoded_key.is_a?(Hash) ? decoded_key : { self.key_field => decoded_key }
44
+
45
+ Utils::SchemaClass.instance(schema_key,
44
46
  "#{@schema}_key",
45
47
  @namespace)
46
48
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '2.0.0-alpha2'
4
+ VERSION = '2.0.0-alpha4'
5
5
  end
data/lib/deimos.rb CHANGED
@@ -162,7 +162,7 @@ module Deimos
162
162
  if topic
163
163
  karafka_configs.find { |t| t.name == topic}
164
164
  elsif producer
165
- karafka_configs.find { |t| t.producer_class == producer}
165
+ karafka_configs.find { |t| t.producer_classes.include?(producer)}
166
166
  end
167
167
  end
168
168
 
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: 2.0.0.pre.alpha2
4
+ version: 2.0.0.pre.alpha4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-29 00:00:00.000000000 Z
11
+ date: 2024-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro_turf