sidekiq-ultimate 0.0.1.alpha.14 → 0.0.1.alpha.15

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: 4edc49fb50c61a2e76976baa800f742bd77792ae24f3f0bf6eca58483a0e9850
4
- data.tar.gz: 743fca3a57ea28a216c7cff903cd2bd71cdb3955fe74d596a80659651aec6781
3
+ metadata.gz: 441f5bf063360de121a2c0f33c4dffe39b2313e841830c786b21812649b465b8
4
+ data.tar.gz: 3a5304085501c4375af4b95c1dfdfd26fe06cbb56756ab55afab0004c97a22ec
5
5
  SHA512:
6
- metadata.gz: 893c060ec92fe0d9fac453deb488b4d6f412bc4034cb25ed68cac3e0323a93ac28700c42e1f009c3636055977b6eaee68a779328bc957462cc17c342d984ff46
7
- data.tar.gz: 2d8e07e65ad4b0ddb2e30a087364c0045ec7d03c3fb53c447289e48a15a339b83e5584b7abe5e7f518e4108c4469510effbddf24ae8009f81eb328f08d74b920
6
+ metadata.gz: df918771242ecaf8c3bab9dfc47cb2992a6bbb0dc1c6ab141c1af1cdb86d5cc10134f95a6ec1d7b735136f718116140037a57b51f50e6b90f8e8adc23012469c
7
+ data.tar.gz: 89a4316a4b869a7758f488575918a3ddb3521c93c9d22f9fc20beaa71350c36e0c8feb268b03c98d2c6f4731c3d8711b9f700ef70a709a2d98c583a4a334aaff
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sidekiq
4
+ module Ultimate
5
+ module Debugging
6
+ private
7
+
8
+ def debug!
9
+ return unless ENV.key? "DEBUG_SIDEKIQ_ULTIMATE"
10
+ Sidekiq.logger.debug { "[#{self.class}] #{yield}" }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -4,6 +4,8 @@ require "monitor"
4
4
 
5
5
  require "concurrent/utility/monotonic_time"
6
6
 
7
+ require "sidekiq/ultimate/debugging"
8
+
7
9
  module Sidekiq
8
10
  module Ultimate
9
11
  # List that tracks when elements were added and enumerates over those not
@@ -31,6 +33,7 @@ module Sidekiq
31
33
  # @private
32
34
  class ExpirableSet
33
35
  include Enumerable
36
+ include Debugging
34
37
 
35
38
  # Create a new ExpirableSet instance.
36
39
  def initialize
@@ -50,9 +53,15 @@ module Sidekiq
50
53
  expires_at = Concurrent.monotonic_time + ttl
51
54
 
52
55
  # do not allow decrease element's expiry
53
- break if @set[element] && @set[element] >= expires_at
54
-
55
- @set[element] = expires_at
56
+ if @set[element] && @set[element] >= expires_at
57
+ debug! do
58
+ "#{element}'s expiry kept as is: #{@set[element]}; " \
59
+ "proposed expiry was: #{expires_at}"
60
+ end
61
+ else
62
+ @set[element] = expires_at
63
+ debug! { "#{element}'s expiry set to: #{expires_at}" }
64
+ end
56
65
  end
57
66
 
58
67
  self
@@ -69,6 +78,9 @@ module Sidekiq
69
78
 
70
79
  @mon.synchronize do
71
80
  horizon = Concurrent.monotonic_time
81
+
82
+ debug! { "Yielding elements above #{horizon} horizon" }
83
+
72
84
  @set.each { |k, v| v < horizon ? @set.delete(k) : yield(k) }
73
85
  end
74
86
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "sidekiq/throttled"
4
4
 
5
+ require "sidekiq/ultimate/debugging"
5
6
  require "sidekiq/ultimate/expirable_set"
6
7
  require "sidekiq/ultimate/queue_name"
7
8
  require "sidekiq/ultimate/resurrector"
@@ -11,12 +12,16 @@ module Sidekiq
11
12
  module Ultimate
12
13
  # Throttled reliable fetcher implementing reliable queue pattern.
13
14
  class Fetch
15
+ include Debugging
16
+
14
17
  # Timeout to sleep between fetch retries in case of no job received.
15
18
  TIMEOUT = 2
16
19
 
20
+ QUEUE_TIMEOUT = 5
21
+
17
22
  # Timeout to sleep between queue fetch attempts in case if last job
18
23
  # of it was throttled.
19
- THROTTLE_TIMEOUT = 10
24
+ THROTTLE_TIMEOUT = 15
20
25
 
21
26
  def initialize(options)
22
27
  @exhausted = ExpirableSet.new
@@ -30,12 +35,16 @@ module Sidekiq
30
35
  def retrieve_work
31
36
  work = retrieve
32
37
 
33
- return unless work
34
- return work unless work.throttled?
38
+ if work&.throttled?
39
+ work.requeue_throttled
35
40
 
36
- work.requeue_throttled
41
+ debug! { "Queue #{queue} got throttled job." }
42
+ @exhausted.add(work.queue, :ttl => THROTTLE_TIMEOUT)
43
+
44
+ return nil
45
+ end
37
46
 
38
- @exhausted.add(work.queue, :ttl => THROTTLE_TIMEOUT)
47
+ work
39
48
  end
40
49
 
41
50
  def self.bulk_requeue(units, _options)
@@ -55,20 +64,25 @@ module Sidekiq
55
64
  job = redis.rpoplpush(queue.pending, queue.inproc)
56
65
  return UnitOfWork.new(queue, job) if job
57
66
 
58
- @exhausted.add(queue, :ttl => TIMEOUT)
67
+ debug! { "Queue #{queue} has no job." }
68
+ @exhausted.add(queue, :ttl => QUEUE_TIMEOUT)
59
69
  end
60
70
  end
61
71
 
72
+ debug! { "No jobs in any queues." }
73
+
62
74
  sleep TIMEOUT
63
75
  nil
64
76
  end
65
77
 
66
78
  def queues
67
- (@strict ? @queues : @queues.shuffle.uniq) - exhausted - paused_queues
68
- end
79
+ queues = @strict ? @queues : @queues.shuffle.uniq
80
+ queues -= @exhausted_queues.to_a
81
+ queues -= paused_queues unless queues.empty?
82
+
83
+ debug! { "Queues to poll: #{queues.map(&:to_s).join(', ')}" }
69
84
 
70
- def exhausted
71
- @exhausted.to_a
85
+ queues
72
86
  end
73
87
 
74
88
  def paused_queues
@@ -32,7 +32,7 @@ module Sidekiq
32
32
  # @param normalized [#to_s] Normalized (without any namespaces or `queue:`
33
33
  # prefixes) queue name.
34
34
  # @param identity [#to_s] Sidekiq process identity.
35
- def initialize(normalized, identity: self.class.process_identity)
35
+ def initialize(normalized, identity: Helper.identity)
36
36
  @normalized = -normalized.to_s
37
37
  @identity = -identity.to_s
38
38
  end
@@ -113,10 +113,6 @@ module Sidekiq
113
113
  def self.[](name, **kwargs)
114
114
  new(name.to_s.sub(QUEUE_PREFIX_RE, "").freeze, **kwargs)
115
115
  end
116
-
117
- def self.process_identity
118
- Helper.identity
119
- end
120
116
  end
121
117
  end
122
118
  end
@@ -95,7 +95,7 @@ module Sidekiq
95
95
  results = redis.pipelined { |r| [r.time, r.get(LAST_RUN_KEY)] }
96
96
  distance = results[0][0] - results[1].to_i
97
97
 
98
- return unless 60 < distance
98
+ break unless 60 < distance
99
99
 
100
100
  yield
101
101
 
@@ -3,6 +3,6 @@
3
3
  module Sidekiq
4
4
  module Ultimate
5
5
  # Gem version.
6
- VERSION = "0.0.1.alpha.14"
6
+ VERSION = "0.0.1.alpha.15"
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.14
4
+ version: 0.0.1.alpha.15
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-27 00:00:00.000000000 Z
11
+ date: 2019-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -112,6 +112,7 @@ files:
112
112
  - README.md
113
113
  - Rakefile
114
114
  - lib/sidekiq/ultimate.rb
115
+ - lib/sidekiq/ultimate/debugging.rb
115
116
  - lib/sidekiq/ultimate/expirable_set.rb
116
117
  - lib/sidekiq/ultimate/fetch.rb
117
118
  - lib/sidekiq/ultimate/queue_name.rb
@@ -141,8 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  - !ruby/object:Gem::Version
142
143
  version: 1.3.1
143
144
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.7.6
145
+ rubygems_version: 3.0.3
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: Sidekiq ultimate experience.