sbmt-outbox 6.0.0 → 6.0.1

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: 818de79692d37138c630bf2fce625a54becf3a8fa71eafe3c5435d573dbcf665
4
- data.tar.gz: 2516c414d14a60851d53fd9f821845179ac12cfb88176a18c1f60d8ba8e38bc9
3
+ metadata.gz: d7ed66a6f328704ae2838f6c0d4b8f6c42788d546d227ef3035d6774bd84e38c
4
+ data.tar.gz: 5e7eac918594e2268757d25aba26d18da783d50d31f5cf61e03bb921c2390e6a
5
5
  SHA512:
6
- metadata.gz: 0e1c0f1f55ef75e5c73352f0789dc51559656f5868a64f2ca8b0c97c10b2865cd37189dc6b3a5d0346673251800ed1c652df951734a5fe77029ca87dbb0fc1a3
7
- data.tar.gz: f0aba9307dcfac3c8e330f1a8a1e40e33439a624c4c40c34ea9223c53c25acff2540ad03c72b00a71c1e963885ecee4e6befc5e5e94d4d78e13ecf6acac4c69e
6
+ metadata.gz: af1f6fa94feb668716256f9a9e4c462585da9341da9823b2d960c5af2e6b392fc4736eb3cfbfb80cc8a255399ba80c01b9b6cdf6f28644dbdbd1538e8342dd94
7
+ data.tar.gz: 35957d9cc3e507b708f6b74cb1da20a687dfd0b251321a03f22245e9de6ebd73ea40cfa5620ffe4a7b6a2822b8411582385ae5681b8fe809165ef2da88f11882
@@ -48,7 +48,7 @@ module Sbmt
48
48
  pc.threads_count = 4
49
49
  pc.general_timeout = 120
50
50
  pc.cutoff_timeout = 60
51
- pc.brpop_delay = 2
51
+ pc.brpop_delay = 1
52
52
  end
53
53
 
54
54
  c.database_switcher = "Sbmt::Outbox::DatabaseSwitcher"
@@ -8,15 +8,36 @@ module Sbmt
8
8
  module V2
9
9
  module PollThrottler
10
10
  class RateLimited < Base
11
+ attr_reader :queues
12
+
11
13
  def initialize(limit: nil, interval: nil, balanced: true)
12
- @queue = Limiter::RateQueue.new(limit, interval: interval, balanced: balanced)
14
+ @limit = limit
15
+ @interval = interval
16
+ @balanced = balanced
17
+ @queues = {}
18
+ @mutex = Mutex.new
13
19
  end
14
20
 
15
- def wait(_worker_num, _poll_task, _task_result)
16
- @queue.shift
21
+ def wait(_worker_num, poll_task, _task_result)
22
+ queue_for(poll_task).shift
17
23
 
18
24
  Success(Sbmt::Outbox::V2::Throttler::THROTTLE_STATUS)
19
25
  end
26
+
27
+ private
28
+
29
+ def queue_for(task)
30
+ key = task.item_class.box_name
31
+ return @queues[key] if @queues.key?(key)
32
+
33
+ @mutex.synchronize do
34
+ return @queues[key] if @queues.key?(key)
35
+
36
+ @queues[key] = Limiter::RateQueue.new(
37
+ @limit, interval: @interval, balanced: @balanced
38
+ )
39
+ end
40
+ end
20
41
  end
21
42
  end
22
43
  end
@@ -12,6 +12,8 @@ module Sbmt
12
12
  delegate :processor_config, :batch_process_middlewares, :logger, to: "Sbmt::Outbox"
13
13
  attr_reader :lock_timeout, :brpop_delay
14
14
 
15
+ REDIS_BRPOP_MIN_DELAY = 0.1
16
+
15
17
  def initialize(
16
18
  boxes,
17
19
  threads_count: nil,
@@ -20,7 +22,7 @@ module Sbmt
20
22
  redis: nil
21
23
  )
22
24
  @lock_timeout = lock_timeout || processor_config.general_timeout
23
- @brpop_delay = brpop_delay || processor_config.brpop_delay
25
+ @brpop_delay = brpop_delay || redis_brpop_delay(boxes.count, processor_config.brpop_delay)
24
26
 
25
27
  super(boxes: boxes, threads_count: threads_count || processor_config.threads_count, name: "processor", redis: redis)
26
28
  end
@@ -95,6 +97,12 @@ module Sbmt
95
97
  def redis_block_timeout
96
98
  redis.read_timeout + brpop_delay
97
99
  end
100
+
101
+ def redis_brpop_delay(boxes_count, default_delay)
102
+ return default_delay if boxes_count == 1
103
+
104
+ REDIS_BRPOP_MIN_DELAY
105
+ end
98
106
  end
99
107
  end
100
108
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sbmt
4
4
  module Outbox
5
- VERSION = "6.0.0"
5
+ VERSION = "6.0.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbmt-outbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sbermarket Ruby-Platform Team