deimos-ruby 2.0.0.pre.alpha2 → 2.0.0.pre.alpha4
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/Gemfile +1 -0
- data/docs/CONFIGURATION.md +15 -14
- data/docs/UPGRADING.md +1 -0
- data/lib/deimos/active_record_producer.rb +1 -1
- data/lib/deimos/ext/consumer_route.rb +2 -1
- data/lib/deimos/ext/producer_route.rb +13 -5
- data/lib/deimos/logging.rb +5 -1
- data/lib/deimos/producer.rb +1 -1
- data/lib/deimos/test_helpers.rb +18 -8
- data/lib/deimos/transcoder.rb +4 -2
- data/lib/deimos/version.rb +1 -1
- data/lib/deimos.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13ff4c1182fe82aa5e41b6981480e463588c64803b060d1ea68aeeded001b945
|
4
|
+
data.tar.gz: 3cd1ff2eac1aa981aeef0c15d399850ffbfb13a71a3315476f62494eaea16f09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0389849fa59d727f6b44d850874e4b6a694e856b9dbfa1624282b77f6113ae31a208f3f41dae677b4563add662b7232462575059b05867298fd40440255d5e3d'
|
7
|
+
data.tar.gz: f03cd3234d22da82ae55976478023b90353823cceea9440aa805cc8994a527867ca1af074c6df2eb99a96f9a0efaa14a8da5bd10a00f5d0bf01c0bf746687333
|
data/Gemfile
CHANGED
data/docs/CONFIGURATION.md
CHANGED
@@ -86,21 +86,22 @@ Deimos.configure do
|
|
86
86
|
end
|
87
87
|
```
|
88
88
|
|
89
|
-
| Config name | Default
|
90
|
-
|
91
|
-
| producer_class | nil
|
92
|
-
|
|
93
|
-
|
|
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
|
96
|
-
| retries | 1
|
97
|
-
| full_table | false
|
98
|
-
| start_from_beginning | true
|
99
|
-
| state_column | nil
|
100
|
-
| publish_timestamp_column | nil
|
101
|
-
| published_state | nil
|
102
|
-
| failed_state | nil
|
103
|
-
| poller_class | nil
|
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.
|
@@ -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.
|
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(
|
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
|
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
|
23
|
+
@deimos_producer_config.send(field)
|
16
24
|
end
|
17
25
|
end
|
18
26
|
end
|
data/lib/deimos/logging.rb
CHANGED
@@ -3,7 +3,11 @@ module Deimos
|
|
3
3
|
class << self
|
4
4
|
|
5
5
|
def log_add(method, msg)
|
6
|
-
Karafka.logger.tagged
|
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
|
|
data/lib/deimos/producer.rb
CHANGED
data/lib/deimos/test_helpers.rb
CHANGED
@@ -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
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
data/lib/deimos/transcoder.rb
CHANGED
@@ -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
|
41
|
+
return decoded_key if self.key_field || !@use_schema_classes
|
42
42
|
|
43
|
-
|
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
|
data/lib/deimos/version.rb
CHANGED
data/lib/deimos.rb
CHANGED
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.
|
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
|
+
date: 2024-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro_turf
|