sidekiq-ultimate 0.0.1.alpha.5 → 0.0.1.alpha.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93e1eaff50e0499819b57d210931b829eaf89c6843ddfeeb3a027a8e3291908f
|
4
|
+
data.tar.gz: 6071458dd821cda0e00891af04801841a62b52e0aea2b4e1523d93b4345fbffe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29e14a9eea62466ca4212f25b475424c864f70146996c7518a0c8115d56d5f8f5c6547af38176e20def8391f10cecb83715363df5f62d2228e68b4854dd5cd1e
|
7
|
+
data.tar.gz: 9aeaf41ebc64f0e3bfa181e8acaaf34e775f0fa47ef58ce71ab81a9917b8681fbdd3db93b75e99a50063381a61cf3b4077d0f0aeb1fb06e259f69f924329e3d5
|
@@ -29,24 +29,32 @@ module Sidekiq
|
|
29
29
|
# @see https://linux.die.net/man/3/clock_gettime
|
30
30
|
#
|
31
31
|
# @private
|
32
|
-
class
|
32
|
+
class ExpirableSet
|
33
33
|
include Enumerable
|
34
34
|
|
35
|
-
# Create a new
|
36
|
-
|
37
|
-
|
38
|
-
def initialize(ttl)
|
39
|
-
@ttl = ttl.to_f
|
40
|
-
@arr = []
|
35
|
+
# Create a new ExpirableSet instance.
|
36
|
+
def initialize
|
37
|
+
@set = {}
|
41
38
|
@mon = Monitor.new
|
42
39
|
end
|
43
40
|
|
44
|
-
|
41
|
+
alias to_ary to_a
|
42
|
+
|
43
|
+
# Adds given element into the set.
|
45
44
|
#
|
46
45
|
# @params element [Object]
|
47
|
-
# @
|
48
|
-
|
49
|
-
|
46
|
+
# @param ttl [Numeric] elements time-to-live in seconds
|
47
|
+
# @return [ExpirableSet] self
|
48
|
+
def add(element, ttl:)
|
49
|
+
@mon.synchronize do
|
50
|
+
expires_at = Concurrent.monotonic_time + ttl
|
51
|
+
|
52
|
+
# do not allow decrease element's expiry
|
53
|
+
break if @set[element] && @set[element] >= expires_at
|
54
|
+
|
55
|
+
@set[element] = expires_at
|
56
|
+
end
|
57
|
+
|
50
58
|
self
|
51
59
|
end
|
52
60
|
|
@@ -55,18 +63,15 @@ module Sidekiq
|
|
55
63
|
#
|
56
64
|
# @yield [element]
|
57
65
|
# @return [Enumerator] if no block given
|
58
|
-
# @return [
|
66
|
+
# @return [ExpirableSet] self if block given
|
59
67
|
def each
|
60
68
|
return to_enum __method__ unless block_given?
|
61
69
|
|
62
|
-
# Evict expired elements
|
63
70
|
@mon.synchronize do
|
64
|
-
horizon = Concurrent.monotonic_time
|
65
|
-
@
|
71
|
+
horizon = Concurrent.monotonic_time
|
72
|
+
@set.each { |k, v| v < horizon ? @set.delete(k) : yield(k) }
|
66
73
|
end
|
67
74
|
|
68
|
-
@arr.dup.each { |element| yield element[1] }
|
69
|
-
|
70
75
|
self
|
71
76
|
end
|
72
77
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "sidekiq/throttled"
|
4
4
|
|
5
|
-
require "sidekiq/ultimate/
|
5
|
+
require "sidekiq/ultimate/expirable_set"
|
6
6
|
require "sidekiq/ultimate/queue_name"
|
7
7
|
require "sidekiq/ultimate/resurrector"
|
8
8
|
require "sidekiq/ultimate/unit_of_work"
|
@@ -11,12 +11,15 @@ module Sidekiq
|
|
11
11
|
module Ultimate
|
12
12
|
# Throttled reliable fetcher implementing reliable queue pattern.
|
13
13
|
class Fetch
|
14
|
-
# Timeout to sleep between fetch retries in case of no job received
|
15
|
-
# as well as timeout to wait for redis to give us something to work.
|
14
|
+
# Timeout to sleep between fetch retries in case of no job received.
|
16
15
|
TIMEOUT = 2
|
17
16
|
|
17
|
+
# Timeout to sleep between queue fetch attempts in case if last job
|
18
|
+
# of it was throttled.
|
19
|
+
THROTTLE_TIMEOUT = 10
|
20
|
+
|
18
21
|
def initialize(options)
|
19
|
-
@exhausted =
|
22
|
+
@exhausted = ExpirableSet.new
|
20
23
|
|
21
24
|
@strict = options[:strict] ? true : false
|
22
25
|
@queues = options[:queues].map { |name| QueueName.new(name) }
|
@@ -31,7 +34,7 @@ module Sidekiq
|
|
31
34
|
return work unless work.throttled?
|
32
35
|
|
33
36
|
work.requeue_throttled
|
34
|
-
@exhausted
|
37
|
+
@exhausted.add(work.queue, :ttl => THROTTLE_TIMEOUT)
|
35
38
|
end
|
36
39
|
|
37
40
|
def self.bulk_requeue(*)
|
@@ -51,7 +54,7 @@ module Sidekiq
|
|
51
54
|
job = redis.rpoplpush(queue.pending, queue.inproc)
|
52
55
|
return UnitOfWork.new(queue, job) if job
|
53
56
|
|
54
|
-
@exhausted
|
57
|
+
@exhausted.add(queue, :ttl => TIMEOUT)
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-ultimate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.alpha.
|
4
|
+
version: 0.0.1.alpha.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Zapparov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -112,7 +112,7 @@ files:
|
|
112
112
|
- README.md
|
113
113
|
- Rakefile
|
114
114
|
- lib/sidekiq/ultimate.rb
|
115
|
-
- lib/sidekiq/ultimate/
|
115
|
+
- lib/sidekiq/ultimate/expirable_set.rb
|
116
116
|
- lib/sidekiq/ultimate/fetch.rb
|
117
117
|
- lib/sidekiq/ultimate/queue_name.rb
|
118
118
|
- lib/sidekiq/ultimate/resurrector.rb
|