sbmt-outbox 6.13.1 → 6.14.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: bcee17041bce58afa1aae1d66f2eaa9fa6d5caf1fd7a120702784e5edf5a397d
4
- data.tar.gz: 0decf4919d3b431b25aab5e05a80c18cf7abb4c30cf74e0ac13f3f96c794b294
3
+ metadata.gz: 2616bf630410714a263f3eea95a7c98af5568018386d0792b8af8ac8de9572b2
4
+ data.tar.gz: 711b190d7c2d45ae1e66f07e60d9742fea6d2f9d0eae07431756da99bbc71e83
5
5
  SHA512:
6
- metadata.gz: c6dc93a04ec8754f9c2a268a954d3cef3418992fa44d27a0c141c68243bbeb411340080154c51dbff2a633554b576546b6d63bb2f66b9ec44eb8dc8b1b910d8a
7
- data.tar.gz: 1b12263dd0ac7b43b01290640ee7fcb6c7dd1b44c8188a68bb77b30ffe5e03dae7f465a133beb09851e2504aceb620143a1e36bd6eb482847d79e134d3ad1b22
6
+ metadata.gz: 8af881dffaa9802491a6764f471a6fedaac2ea5766e1f2c6749a1b6f5523f74f5f2239025b6d1e48fd985243556569b1670ed80d5aeb92f0a40ae67c2254a777
7
+ data.tar.gz: 543ad28b03629931934332ef0f62a6190a90159c0aa45ef3800c09472a824bfd474f270a5c9d27df2879ace34d2f03bbc92206381476568313254cf8db34a70a
data/README.md CHANGED
@@ -267,8 +267,12 @@ default: &default
267
267
  outbox_items: # outbox items section
268
268
  my_outbox_item: # underscored model class name
269
269
  owner: my_outbox_item_team # optional, used in Yabeda metrics
270
- retention: P1W # for statuses: failed and discarded, retention period, https://en.wikipedia.org/wiki/ISO_8601#Durations
271
- retention_delivered_items: PT6H # for statuses: delivered, retention period for delivered items, https://en.wikipedia.org/wiki/ISO_8601#Durations
270
+ retention: P1W #optional, default: P1W, for statuses: failed and discarded, retention period, https://en.wikipedia.org/wiki/ISO_8601#Durations
271
+ min_retention_period: P1D #optional, default: P1D, for statuses: failed and discarded, retention period, https://en.wikipedia.org/wiki/ISO_8601#Durations
272
+ retention_delivered_items: PT6H #optional, default: P1W, for statuses: delivered, retention period for delivered items, https://en.wikipedia.org/wiki/ISO_8601#Durations
273
+ delivered_min_retention_period: PT1H #optional, default: PT1H, for statuses: delivered, retention period for delivered items, https://en.wikipedia.org/wiki/ISO_8601#Durations
274
+ deletion_batch_size: 1_000 #optional, default: 1_000
275
+ deletion_sleep_time: 0.5 #optional, default: 0.5
272
276
  max_retries: 3 # default 0, the number of retries before the item will be marked as failed
273
277
  strict_order: false # optional, default
274
278
  transports: # transports section
@@ -343,8 +347,12 @@ end
343
347
  inbox_items: # inbox items section
344
348
  my_inbox_item: # underscored model class name
345
349
  owner: my_inbox_item_team # optional, used in Yabeda metrics
346
- retention: P1W # for statuses: failed and discarded, retention period, https://en.wikipedia.org/wiki/ISO_8601#Durations
347
- retention_delivered_items: PT6H # for statuses: delivered, retention period for delivered items, https://en.wikipedia.org/wiki/ISO_8601#Durations
350
+ retention: P1W #optional, default: P1W, for statuses: failed and discarded, retention period, https://en.wikipedia.org/wiki/ISO_8601#Durations
351
+ min_retention_period: P1D #optional, default: P1D, for statuses: failed and discarded, retention period, https://en.wikipedia.org/wiki/ISO_8601#Durations
352
+ retention_delivered_items: PT6H #optional, default: P1W, for statuses: delivered, retention period for delivered items, https://en.wikipedia.org/wiki/ISO_8601#Durations
353
+ delivered_min_retention_period: PT1H #optional, default: PT1H, for statuses: delivered, retention period for delivered items, https://en.wikipedia.org/wiki/ISO_8601#Durations
354
+ deletion_batch_size: 1_000 #optional, default: 1_000
355
+ deletion_sleep_time: 0.5 #optional, default: 0.5
348
356
  max_retries: 3 # default 0, the number of retries before the item will be marked as failed
349
357
  transports: # transports section
350
358
  import_order: # underscored transport class name
@@ -5,10 +5,7 @@ require "redlock"
5
5
  module Sbmt
6
6
  module Outbox
7
7
  class BaseDeleteStaleItemsJob < Outbox.active_job_base_class
8
- MIN_RETENTION_PERIOD = 1.day
9
8
  LOCK_TTL = 10_800_000
10
- BATCH_SIZE = 1_000
11
- SLEEP_TIME = 0.5
12
9
 
13
10
  class << self
14
11
  def enqueue
@@ -45,7 +42,7 @@ module Sbmt
45
42
  duration_failed = item_class.config.retention
46
43
  duration_delivered = item_class.config.retention_delivered_items
47
44
 
48
- validate_retention!(duration_failed)
45
+ validate_retention!(duration_delivered, duration_failed)
49
46
 
50
47
  logger.with_tags(box_type: box_type, box_name: box_name) do
51
48
  delete_stale_items(Time.current - duration_failed, Time.current - duration_delivered)
@@ -60,10 +57,22 @@ module Sbmt
60
57
 
61
58
  private
62
59
 
63
- def validate_retention!(duration_failed)
64
- return if duration_failed >= MIN_RETENTION_PERIOD
60
+ def validate_retention!(duration_delivered, duration_failed)
61
+ validate_retention_for!(
62
+ duration: duration_delivered,
63
+ min_period: item_class.config.delivered_min_retention_period,
64
+ error_message: "Retention period for #{box_name} must be longer than #{item_class.config.delivered_min_retention_period.inspect}"
65
+ )
66
+
67
+ validate_retention_for!(
68
+ duration: duration_failed,
69
+ min_period: item_class.config.min_retention_period,
70
+ error_message: "Retention period for #{box_name} must be longer than #{item_class.config.min_retention_period.inspect}"
71
+ )
72
+ end
65
73
 
66
- raise "Retention period for #{box_name} must be longer than #{MIN_RETENTION_PERIOD.inspect}"
74
+ def validate_retention_for!(duration:, min_period:, error_message:)
75
+ raise error_message if duration < min_period
67
76
  end
68
77
 
69
78
  def delete_stale_items(waterline_failed, waterline_delivered)
@@ -111,7 +120,7 @@ module Sbmt
111
120
  subquery = table
112
121
  .project(table[:id])
113
122
  .where(condition)
114
- .take(BATCH_SIZE)
123
+ .take(item_class.config.deletion_batch_size)
115
124
 
116
125
  delete_statement = Arel::Nodes::DeleteStatement.new
117
126
  delete_statement.relation = table
@@ -131,7 +140,7 @@ module Sbmt
131
140
  logger.log_info("Deleted #{deleted_count} #{box_type} items for #{box_name} items")
132
141
  break if deleted_count == 0
133
142
  lock_timer.checkpoint!
134
- sleep(SLEEP_TIME)
143
+ sleep(item_class.config.deletion_sleep_time)
135
144
  end
136
145
  end
137
146
 
@@ -167,7 +176,7 @@ module Sbmt
167
176
 
168
177
  loop do
169
178
  track_deleted_latency do
170
- deleted_count = query.limit(BATCH_SIZE).delete_all
179
+ deleted_count = query.limit(item_class.config.deletion_batch_size).delete_all
171
180
  end
172
181
 
173
182
  track_deleted_counter(deleted_count)
@@ -175,7 +184,7 @@ module Sbmt
175
184
  logger.log_info("Deleted #{deleted_count} #{box_type} items for #{box_name} items")
176
185
  break if deleted_count == 0
177
186
  lock_timer.checkpoint!
178
- sleep(SLEEP_TIME)
187
+ sleep(item_class.config.deletion_sleep_time)
179
188
  end
180
189
  end
181
190
 
@@ -44,6 +44,22 @@ module Sbmt
44
44
  end
45
45
  end
46
46
 
47
+ def deletion_batch_size
48
+ @deletion_batch_size ||= (options[:deletion_batch_size] || 1_000).to_i
49
+ end
50
+
51
+ def deletion_sleep_time
52
+ @deletion_sleep_time ||= (options[:deletion_sleep_time] || 0.5).to_f
53
+ end
54
+
55
+ def min_retention_period
56
+ @min_retention_period ||= ActiveSupport::Duration.parse(options[:min_retention_period] || "P1D")
57
+ end
58
+
59
+ def delivered_min_retention_period
60
+ @delivered_min_retention_period ||= ActiveSupport::Duration.parse(options[:delivered_min_retention_period] || "PT1H")
61
+ end
62
+
47
63
  def max_retries
48
64
  @max_retries ||= (options[:max_retries] || 0).to_i
49
65
  end
@@ -17,6 +17,11 @@ default: &default
17
17
  # partition_size: 2
18
18
  # partition_strategy: number
19
19
  # retention: P1W
20
+ # min_retention_period: P1D
21
+ # retention_delivered_items: PT6H
22
+ # delivered_min_retention_period: PT1H
23
+ # deletion_batch_size: 1_000
24
+ # deletion_sleep_time: 0.5
20
25
  # retry_strategies:
21
26
  # - exponential_backoff
22
27
  # - compacted_log
@@ -32,6 +37,11 @@ default: &default
32
37
  # partition_size: 2
33
38
  # partition_strategy: number
34
39
  # retention: P1W
40
+ # min_retention_period: P1D
41
+ # retention_delivered_items: PT6H
42
+ # delivered_min_retention_period: PT1H
43
+ # deletion_batch_size: 1_000
44
+ # deletion_sleep_time: 0.5
35
45
  # retry_strategies:
36
46
  # - exponential_backoff
37
47
  # transports:
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sbmt
4
4
  module Outbox
5
- VERSION = "6.13.1"
5
+ VERSION = "6.14.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.13.1
4
+ version: 6.14.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: 2025-01-15 00:00:00.000000000 Z
11
+ date: 2025-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool