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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7ed66a6f328704ae2838f6c0d4b8f6c42788d546d227ef3035d6774bd84e38c
|
4
|
+
data.tar.gz: 5e7eac918594e2268757d25aba26d18da783d50d31f5cf61e03bb921c2390e6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af1f6fa94feb668716256f9a9e4c462585da9341da9823b2d960c5af2e6b392fc4736eb3cfbfb80cc8a255399ba80c01b9b6cdf6f28644dbdbd1538e8342dd94
|
7
|
+
data.tar.gz: 35957d9cc3e507b708f6b74cb1da20a687dfd0b251321a03f22245e9de6ebd73ea40cfa5620ffe4a7b6a2822b8411582385ae5681b8fe809165ef2da88f11882
|
data/lib/sbmt/outbox/engine.rb
CHANGED
@@ -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
|
-
@
|
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,
|
16
|
-
|
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
|
data/lib/sbmt/outbox/version.rb
CHANGED