sidekiq-ultimate 0.0.1.alpha.5 → 0.0.1.alpha.6

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: 3f0176019d0fa6bd44ec34fb292e7caafdaa78ab4c8d5dc33c03f2f933b5db74
4
- data.tar.gz: ab8225dae6c14e67784ef3147cad83e1d1597df234626837207d6fd8ba783997
3
+ metadata.gz: 93e1eaff50e0499819b57d210931b829eaf89c6843ddfeeb3a027a8e3291908f
4
+ data.tar.gz: 6071458dd821cda0e00891af04801841a62b52e0aea2b4e1523d93b4345fbffe
5
5
  SHA512:
6
- metadata.gz: d222fcb849ad439eddb9957c6b4fc9c87010181e5b97dc217eaf512402902137671141f090ab3a431fba12d13c145e11d5c6bcd477c94319e267daebfcbfeb97
7
- data.tar.gz: f5ec33ba4bbf1159ec79f12dc4c416f6a79b77f64c4f161bf85690f40173702c513e475884e84dc127a24bc6373b32dc8e84bd59e64dcab36cfd45e8b48ab946
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 ExpirableList
32
+ class ExpirableSet
33
33
  include Enumerable
34
34
 
35
- # Create a new ExpirableList instance.
36
- #
37
- # @param ttl [Float] elements time-to-live in seconds
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
- # Pushes given element into the list.
41
+ alias to_ary to_a
42
+
43
+ # Adds given element into the set.
45
44
  #
46
45
  # @params element [Object]
47
- # @return [ExpirableList] self
48
- def <<(element)
49
- @mon.synchronize { @arr << [Concurrent.monotonic_time, element] }
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 [ExpirableList] self if block given
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 - @ttl
65
- @arr.shift while @arr[0] && @arr[0][0] < horizon
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/expirable_list"
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 = ExpirableList.new(2 * TIMEOUT)
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 << work.queue
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 << queue
57
+ @exhausted.add(queue, :ttl => TIMEOUT)
55
58
  end
56
59
  end
57
60
 
@@ -3,6 +3,6 @@
3
3
  module Sidekiq
4
4
  module Ultimate
5
5
  # Gem version.
6
- VERSION = "0.0.1.alpha.5"
6
+ VERSION = "0.0.1.alpha.6"
7
7
  end
8
8
  end
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.5
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-02-27 00:00:00.000000000 Z
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/expirable_list.rb
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