rails-transactional-outbox 0.3.0 → 0.4.0
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/.rubocop.yml +3 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +3 -3
- data/README.md +2 -0
- data/lib/rails_transactional_outbox/configuration.rb +16 -1
- data/lib/rails_transactional_outbox/outbox_model.rb +2 -1
- data/lib/rails_transactional_outbox/record_processors/active_record_processor.rb +6 -1
- data/lib/rails_transactional_outbox/version.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: 20d98c7e305f01ecd8e54b92170a117c01a412d050acab60899835b99a0d7d0c
|
4
|
+
data.tar.gz: 1658aadc54b3a01dd1e48274055befa210638df3b1fdc60bdd5a0bb2f858e1ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75c6ef520d685476d27fc71f3c3bcac986248ab5d62addd2840238ed020136622cea9c4d20f0ade4fe6d693ffa3545531152d4a57465b72a6cb7a91112a2d5d0
|
7
|
+
data.tar.gz: 9efa9ef99b4c610f89c9ae22d2b5bd0592c0535667d46636e69a8d219cb3e92dda648d315ccf56ca8cfe01f3ae9ccb8588d4f51742072a6309829a68da33614e
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.4.0] - 2024-01-25
|
4
|
+
|
5
|
+
- add config option to specify causality keys limit
|
6
|
+
|
7
|
+
## [0.3.1] - 2023-05-24
|
8
|
+
|
9
|
+
- add config option whether to raise error when outbox entry record is not found
|
10
|
+
|
3
11
|
## [0.3.0] - 2022-12-20
|
4
12
|
|
5
13
|
- Move to file-based healthchecks, instead of using Redis-based ones.
|
data/Gemfile.lock
CHANGED
@@ -9,7 +9,7 @@ GIT
|
|
9
9
|
PATH
|
10
10
|
remote: .
|
11
11
|
specs:
|
12
|
-
rails-transactional-outbox (0.
|
12
|
+
rails-transactional-outbox (0.4.0)
|
13
13
|
activerecord (>= 5)
|
14
14
|
activesupport (>= 3.2)
|
15
15
|
concurrent-ruby
|
@@ -55,7 +55,7 @@ GEM
|
|
55
55
|
dry-events (~> 1.0, < 2)
|
56
56
|
exponential-backoff (0.0.4)
|
57
57
|
ffi (1.15.5)
|
58
|
-
file-based-healthcheck (0.
|
58
|
+
file-based-healthcheck (0.2.0)
|
59
59
|
activesupport (>= 3.2)
|
60
60
|
i18n (1.12.0)
|
61
61
|
concurrent-ruby (~> 1.0)
|
@@ -121,7 +121,7 @@ GEM
|
|
121
121
|
tzinfo (2.0.5)
|
122
122
|
concurrent-ruby (~> 1.0)
|
123
123
|
unicode-display_width (2.2.0)
|
124
|
-
zeitwerk (2.6.
|
124
|
+
zeitwerk (2.6.12)
|
125
125
|
|
126
126
|
PLATFORMS
|
127
127
|
x86_64-darwin-18
|
data/README.md
CHANGED
@@ -39,11 +39,13 @@ Rails.application.config.to_prepare do
|
|
39
39
|
config.transactional_outbox_worker_idle_delay_multiplier = 5 # optional, defaults to 1, if there are no outbox entries to be processed, then the sleep time for the thread will be equal to transactional_outbox_worker_idle_delay_multiplier * transactional_outbox_worker_sleep_seconds
|
40
40
|
config.outbox_batch_size = 100 # optional, defaults to 100
|
41
41
|
config.add_record_processor(MyCustomOperationProcerssor) # optional, by default it contains only one processor for ActiveRecord, but you could add more
|
42
|
+
config.raise_not_found_model_error = true # optional, defaults to true. Should the error be raised if outbox entry model is not found
|
42
43
|
|
43
44
|
config.lock_client = Redlock::Client.new([ENV["REDIS_URL"]]) # required if you want to use RailsTransactionalOutbox::OutboxEntriesProcessors::OrderedByCausalityKeyProcessor, defaults to RailsTransactionalOutbox::NullLockClient. Check its interface and the interface of `redlock` gem. To cut the long story short, when the lock is acquired, a hash with the structure outlined in RailsTransactionalOutbox::NullLockClient should be yielded, if the lock is not acquired, a nil should be yielded.
|
44
45
|
config.lock_expiry_time = 10_000 # not required, defaults to 10_000, the unit is milliseconds
|
45
46
|
config.outbox_entries_processor = `RailsTransactionalOutbox::OutboxEntriesProcessors::OrderedByCausalityKeyProcessor`.new # not required, defaults to RailsTransactionalOutbox::OutboxEntriesProcessors::NonOrderedProcessor.new
|
46
47
|
config.outbox_entry_causality_key_resolver = ->(model) { model.tenant_id } # not required, defaults to a lambda returning nil. Needed when using `outbox_entry_causality_key_resolver`
|
48
|
+
config.unprocessed_causality_keys_limit = 100_000 # not required, defaults to 10_000. Might be a good idea to decrease the value when you start experiencing OOMs - they are likely to be caused by fetching too many causality keys. It is likely to happen when you have huge amount of records to process.
|
47
49
|
end
|
48
50
|
end
|
49
51
|
```
|
@@ -5,7 +5,8 @@ class RailsTransactionalOutbox
|
|
5
5
|
attr_accessor :database_connection_provider, :logger, :outbox_model, :transaction_provider
|
6
6
|
attr_writer :error_handler, :transactional_outbox_worker_sleep_seconds,
|
7
7
|
:transactional_outbox_worker_idle_delay_multiplier, :outbox_batch_size, :outbox_entries_processor,
|
8
|
-
:lock_client, :lock_expiry_time, :outbox_entry_causality_key_resolver
|
8
|
+
:lock_client, :lock_expiry_time, :outbox_entry_causality_key_resolver,
|
9
|
+
:raise_not_found_model_error, :unprocessed_causality_keys_limit
|
9
10
|
|
10
11
|
def error_handler
|
11
12
|
@error_handler || RailsTransactionalOutbox::ErrorHandlers::NullErrorHandler
|
@@ -35,6 +36,14 @@ class RailsTransactionalOutbox
|
|
35
36
|
@outbox_entries_processor ||= RailsTransactionalOutbox::OutboxEntriesProcessors::NonOrderedProcessor.new
|
36
37
|
end
|
37
38
|
|
39
|
+
def raise_not_found_model_error
|
40
|
+
return @raise_not_found_model_error if defined?(@raise_not_found_model_error)
|
41
|
+
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :raise_not_found_model_error?, :raise_not_found_model_error
|
46
|
+
|
38
47
|
def lock_client
|
39
48
|
@lock_client || RailsTransactionalOutbox::NullLockClient
|
40
49
|
end
|
@@ -46,5 +55,11 @@ class RailsTransactionalOutbox
|
|
46
55
|
def outbox_entry_causality_key_resolver
|
47
56
|
@outbox_entry_causality_key_resolver || ->(_model) {}
|
48
57
|
end
|
58
|
+
|
59
|
+
def unprocessed_causality_keys_limit
|
60
|
+
return @unprocessed_causality_keys_limit.to_i if defined?(@unprocessed_causality_keys_limit)
|
61
|
+
|
62
|
+
10_000
|
63
|
+
end
|
49
64
|
end
|
50
65
|
end
|
@@ -24,9 +24,10 @@ class RailsTransactionalOutbox
|
|
24
24
|
.where("retry_at IS NULL OR retry_at <= ?", Time.current)
|
25
25
|
}
|
26
26
|
|
27
|
-
def self.unprocessed_causality_keys
|
27
|
+
def self.unprocessed_causality_keys(limit: RailsTransactionalOutbox.configuration.unprocessed_causality_keys_limit)
|
28
28
|
processable_now
|
29
29
|
.select("causality_key")
|
30
|
+
.limit(limit)
|
30
31
|
.distinct
|
31
32
|
.pluck(:causality_key)
|
32
33
|
end
|
@@ -15,7 +15,12 @@ class RailsTransactionalOutbox
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def call(record)
|
18
|
-
model = record.infer_model
|
18
|
+
model = record.infer_model
|
19
|
+
if model.nil?
|
20
|
+
raise CouldNotFindModelError.new(record) if RailsTransactionalOutbox.configuration.raise_not_found_model_error?
|
21
|
+
|
22
|
+
return
|
23
|
+
end
|
19
24
|
model.previous_changes = record.transformed_changeset.with_indifferent_access
|
20
25
|
model.reliable_after_commit_callbacks.for_event_type(record.event_type).each do |callback|
|
21
26
|
callback.call(model)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-transactional-outbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karol Galanciak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|