rails-transactional-outbox 0.3.0 → 0.4.0

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: 7981d03fa1319ccf83fe5f66ac64869ef024e8add13de49f6af43b26ff39ac3e
4
- data.tar.gz: e2f5048f5c4f5700b95b247064cc4e2fe9d8601b6df63d39b1e06896aeb1e915
3
+ metadata.gz: 20d98c7e305f01ecd8e54b92170a117c01a412d050acab60899835b99a0d7d0c
4
+ data.tar.gz: 1658aadc54b3a01dd1e48274055befa210638df3b1fdc60bdd5a0bb2f858e1ae
5
5
  SHA512:
6
- metadata.gz: e903bcb6ee6c1b58d77b7c9b0dff41297e44b81c45457df0888caf6ecbdf2fa0f7254f9424cac14db2d31933e6f9790438cf2a9e232cb6af06405f9985221ceb
7
- data.tar.gz: 8296fbab0324e8b0fa6410187e0fb59392121aecfccab2301fecff8fc1b51d815eaa71af78fdbd1d7c67f11573fc06d9598ec9e719d01738fc72d92646a33e0a
6
+ metadata.gz: 75c6ef520d685476d27fc71f3c3bcac986248ab5d62addd2840238ed020136622cea9c4d20f0ade4fe6d693ffa3545531152d4a57465b72a6cb7a91112a2d5d0
7
+ data.tar.gz: 9efa9ef99b4c610f89c9ae22d2b5bd0592c0535667d46636e69a8d219cb3e92dda648d315ccf56ca8cfe01f3ae9ccb8588d4f51742072a6309829a68da33614e
data/.rubocop.yml CHANGED
@@ -151,3 +151,6 @@ RSpec/AnyInstance:
151
151
  RSpec/VerifiedDoubles:
152
152
  Exclude:
153
153
  - 'spec/rails_transactional_outbox/runner_spec.rb'
154
+
155
+ Layout/LineLength:
156
+ Max: 125
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.3.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.1.1)
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.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 or raise CouldNotFindModelError.new(record)
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)
@@ -3,5 +3,5 @@
3
3
  class RailsTransactionalOutbox
4
4
  module Version
5
5
  end
6
- VERSION = "0.3.0"
6
+ VERSION = "0.4.0"
7
7
  end
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.3.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: 2022-12-20 00:00:00.000000000 Z
11
+ date: 2024-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord