sbmt-outbox 6.4.3 → 6.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17535824e7b8a62fa7695b25c1be0b53b0bcfb7bff9b8015fec31aaed28ca95b
4
- data.tar.gz: d668f93fe5109170fc1571bd88ccf503f3bc776e406fc32d3ffe1ec130097a8d
3
+ metadata.gz: a86388ca6b13cdaef9411bd8baf1ea045fcc1b941721cdb8d4fb15bda4db29be
4
+ data.tar.gz: 6fbc5a6e5d62df9aaf1cf2f0afdc3cf49e8bf5ccdc0a49d86a0b8feb8e51f200
5
5
  SHA512:
6
- metadata.gz: 80ce2a3aad22f1fa4244d4a86fe8682858abe605bfcf8ac2751a8688fad87f14f7cc141f6ead9ea4e8e47137d95639d3d984724dac31867a4878881f90054786
7
- data.tar.gz: 4dca4cbe2d50415fcf76f5db3243484ad52e9adfbb0a9ac6947bd1cd134e50558cba7432a20782dd5fdd91c95185005312602fefda976a7c48a4b9e0969abde8
6
+ metadata.gz: bca4330c17aa8d6d8f6563ebc52dae02d9029fb01580b9294ffd5d20822768f95f5c41a0c5bdd733d9f6481632f44a754ce67079cf843e9cf3c58ada9f9fbb39
7
+ data.tar.gz: 3c24bf5fa9af05b1ef48f38ff20519466c5f63a47a1acbb5bf788d7e197c8af17759581c52443b8650c8ff4f3680bbd48aee3a8b224623e6097176aa284c5a11
data/README.md CHANGED
@@ -122,7 +122,7 @@ Rails.application.config.outbox.tap do |config|
122
122
  config.paths << Rails.root.join("config/outbox.yml").to_s # optional; configuration file paths, deep merged at the application start, useful with Rails engines
123
123
 
124
124
  # optional (worker v2: default)
125
- c.poller = ActiveSupport::OrderedOptions.new.tap do |pc|
125
+ config.poller = ActiveSupport::OrderedOptions.new.tap do |pc|
126
126
  # max parallel threads (per box-item, globally)
127
127
  pc.concurrency = 6
128
128
  # max threads count (per worker process)
@@ -152,7 +152,7 @@ Rails.application.config.outbox.tap do |config|
152
152
  end
153
153
 
154
154
  # optional (worker v2: default)
155
- c.processor = ActiveSupport::OrderedOptions.new.tap do |pc|
155
+ config.processor = ActiveSupport::OrderedOptions.new.tap do |pc|
156
156
  # max threads count (per worker process)
157
157
  pc.threads_count = 4
158
158
  # maximum processing time of the batch, after which the batch will be considered hung and processing will be aborted
@@ -236,6 +236,7 @@ default: &default
236
236
  owner: my_outbox_item_team # optional, used in Yabeda metrics
237
237
  retention: P1W # retention period, https://en.wikipedia.org/wiki/ISO_8601#Durations
238
238
  max_retries: 3 # default 0, the number of retries before the item will be marked as failed
239
+ strict_order: false # optional, default
239
240
  transports: # transports section
240
241
  produce_message: # underscored transport class name
241
242
  # transport reserved options
@@ -255,6 +256,10 @@ production:
255
256
  <<: *default
256
257
  bucket_size: 256
257
258
  ```
259
+ __CAUTION__:
260
+ - ⚠️ If this option is enabled and an error occurs while processing a message in a bucket,
261
+ subsequent messages in that bucket won't be processed until the current message is either skipped or successfully processed
262
+ - ⚠️ Cannot use `retry_strategies` and the `strict_order` option at the same time
258
263
 
259
264
  ```ruby
260
265
  # app/services/import_order.rb
@@ -64,9 +64,12 @@ module Sbmt
64
64
  def delete_stale_items(waterline)
65
65
  logger.log_info("Start deleting #{box_type} items for #{box_name} older than #{waterline}")
66
66
 
67
- scope = item_class.where("created_at < ?", waterline)
67
+ loop do
68
+ ids = Outbox.database_switcher.use_slave do
69
+ item_class.where("created_at < ?", waterline).limit(BATCH_SIZE).ids
70
+ end
71
+ break if ids.empty?
68
72
 
69
- while (ids = scope.limit(BATCH_SIZE).ids).present?
70
73
  item_class.where(id: ids).delete_all
71
74
  sleep SLEEP_TIME
72
75
  end
@@ -6,7 +6,7 @@ module Sbmt
6
6
  self.abstract_class = true
7
7
 
8
8
  class << self
9
- delegate :owner, to: :config
9
+ delegate :owner, :strict_order, to: :config
10
10
 
11
11
  def box_type
12
12
  raise NotImplementedError
@@ -134,6 +134,7 @@ module Sbmt
134
134
  end
135
135
 
136
136
  def max_retries_exceeded?
137
+ return false if config.strict_order
137
138
  return true unless retriable?
138
139
 
139
140
  errors_count > config.max_retries
@@ -16,7 +16,7 @@ module Sbmt
16
16
  end
17
17
 
18
18
  def owner
19
- return @owner if defined? @owner
19
+ return @owner if defined?(@owner)
20
20
 
21
21
  @owner = options[:owner].presence || yaml_config[:owner].presence
22
22
  end
@@ -57,7 +57,14 @@ module Sbmt
57
57
  return @retry_strategies if defined?(@retry_strategies)
58
58
 
59
59
  configured_strategies = options[:retry_strategies]
60
- strategies = configured_strategies.presence || %w[exponential_backoff latest_available]
60
+
61
+ raise ConfigError, "You cannot use retry_strategies and the strict_order option at the same time." if strict_order.present? && configured_strategies.present?
62
+
63
+ strategies = if strict_order.present? && configured_strategies.nil?
64
+ []
65
+ else
66
+ configured_strategies.presence || %w[exponential_backoff latest_available]
67
+ end
61
68
 
62
69
  @retry_strategies ||= Array.wrap(strategies).map do |str_name|
63
70
  "Sbmt::Outbox::RetryStrategies::#{str_name.camelize}".constantize
@@ -108,6 +115,12 @@ module Sbmt
108
115
  end
109
116
  end
110
117
 
118
+ def strict_order
119
+ return @strict_order if defined?(@strict_order)
120
+
121
+ @strict_order = options[:strict_order].presence
122
+ end
123
+
111
124
  private
112
125
 
113
126
  attr_accessor :box_id, :box_name
@@ -94,7 +94,7 @@ module Sbmt
94
94
  end
95
95
  end
96
96
  rescue Cutoff::CutoffExceededError
97
- box_worker.job_timeout_counter.increment(labels)
97
+ box_worker.job_timeout_counter.increment(task.yabeda_labels)
98
98
  logger.log_info("Lock timeout while processing #{task.resource_key} at id #{last_id}")
99
99
  end
100
100
 
@@ -68,15 +68,18 @@ module Sbmt
68
68
  def process(task)
69
69
  lock_timer = Cutoff.new(lock_timeout)
70
70
  last_id = 0
71
+ strict_order = task.item_class.config.strict_order
71
72
 
72
73
  box_worker.item_execution_runtime.measure(task.yabeda_labels) do
73
74
  Outbox.database_switcher.use_master do
74
75
  task.ids.each do |id|
75
- ProcessItem.call(task.item_class, id, worker_version: task.yabeda_labels[:worker_version])
76
+ result = ProcessItem.call(task.item_class, id, worker_version: task.yabeda_labels[:worker_version])
76
77
 
77
78
  box_worker.job_items_counter.increment(task.yabeda_labels)
78
79
  last_id = id
79
80
  lock_timer.checkpoint!
81
+
82
+ break if strict_order == true && result.failure?
80
83
  end
81
84
  end
82
85
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sbmt
4
4
  module Outbox
5
- VERSION = "6.4.3"
5
+ VERSION = "6.6.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbmt-outbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.4.3
4
+ version: 6.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sbermarket Ruby-Platform Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-16 00:00:00.000000000 Z
11
+ date: 2024-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool