sidekiq-throttled 1.0.0.alpha → 1.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sidekiq/throttled/patches/basic_fetch.rb +60 -0
- data/lib/sidekiq/throttled/strategy_collection.rb +1 -2
- data/lib/sidekiq/throttled/version.rb +1 -1
- data/lib/sidekiq/throttled.rb +2 -10
- metadata +5 -6
- data/lib/sidekiq/throttled/basic_fetch.rb +0 -55
- data/lib/sidekiq/throttled/fetch.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 714915692e57a08eeea5dd0e0be79f3becfa915669f559f3457509073b89e4fe
|
4
|
+
data.tar.gz: 190b4e6d013712725bb64277c00c74c82da5149f73368dbb19890090d638a372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7627db53db315ec4acdaf15e715186522c3dbbdc4084aadd65cd0f081845b247f92eb106bcf2e5bf41b5098400adaed00377104b21205b5914495bcacff9d625
|
7
|
+
data.tar.gz: 1caca54490b41115389b6ce111c4264a911aba84f656546bce0c62846d6f3828c91a1c681bfb0520f04230c6e113b9d1cd5553c500e6a65a7f6d77c2d36903a2
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sidekiq"
|
4
|
+
require "sidekiq/fetch"
|
5
|
+
|
6
|
+
module Sidekiq
|
7
|
+
module Throttled
|
8
|
+
module Patches
|
9
|
+
module BasicFetch
|
10
|
+
class << self
|
11
|
+
def apply!
|
12
|
+
Sidekiq::BasicFetch.prepend(self) unless Sidekiq::BasicFetch.include?(self)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Retrieves job from redis.
|
17
|
+
#
|
18
|
+
# @return [Sidekiq::Throttled::UnitOfWork, nil]
|
19
|
+
def retrieve_work
|
20
|
+
work = super
|
21
|
+
|
22
|
+
if work && Throttled.throttled?(work.job)
|
23
|
+
requeue_throttled(work)
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
|
27
|
+
work
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Pushes job back to the head of the queue, so that job won't be tried
|
33
|
+
# immediately after it was requeued (in most cases).
|
34
|
+
#
|
35
|
+
# @note This is triggered when job is throttled. So it is same operation
|
36
|
+
# Sidekiq performs upon `Sidekiq::Worker.perform_async` call.
|
37
|
+
#
|
38
|
+
# @return [void]
|
39
|
+
def requeue_throttled(work)
|
40
|
+
redis { |conn| conn.lpush(work.queue, work.job) }
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns list of queues to try to fetch jobs from.
|
44
|
+
#
|
45
|
+
# @note It may return an empty array.
|
46
|
+
# @param [Array<String>] queues
|
47
|
+
# @return [Array<String>]
|
48
|
+
def queues_cmd
|
49
|
+
queues = super
|
50
|
+
|
51
|
+
# TODO: Refactor to be prepended as an integration mixin during configuration stage
|
52
|
+
# Or via configurable queues reducer
|
53
|
+
queues -= Sidekiq::Pauzer.paused_queues.map { |name| "queue:#{name}" } if defined?(Sidekiq::Pauzer)
|
54
|
+
|
55
|
+
queues
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -19,8 +19,7 @@ module Sidekiq
|
|
19
19
|
# @param [#to_s] name
|
20
20
|
# @param [#call] key_suffix Dynamic key suffix generator.
|
21
21
|
def initialize(strategies, strategy:, name:, key_suffix:)
|
22
|
-
strategies = (strategies.is_a?(Hash) ? [strategies] : Array(strategies))
|
23
|
-
@strategies = strategies.map do |options|
|
22
|
+
@strategies = (strategies.is_a?(Hash) ? [strategies] : Array(strategies)).map do |options|
|
24
23
|
make_strategy(strategy, name, key_suffix, options)
|
25
24
|
end
|
26
25
|
end
|
data/lib/sidekiq/throttled.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# 3rd party
|
4
3
|
require "sidekiq"
|
5
4
|
|
6
|
-
# internal
|
7
5
|
require_relative "./throttled/version"
|
8
6
|
require_relative "./throttled/configuration"
|
9
|
-
require_relative "./throttled/
|
7
|
+
require_relative "./throttled/patches/basic_fetch"
|
10
8
|
require_relative "./throttled/registry"
|
11
9
|
require_relative "./throttled/job"
|
12
10
|
require_relative "./throttled/middleware"
|
@@ -52,13 +50,7 @@ module Sidekiq
|
|
52
50
|
#
|
53
51
|
# @return [void]
|
54
52
|
def setup!
|
55
|
-
Sidekiq.
|
56
|
-
if Gem::Version.new("7.0.0") <= Gem::Version.new(Sidekiq::VERSION)
|
57
|
-
config[:fetch_class] = Sidekiq::Throttled::Fetch
|
58
|
-
else
|
59
|
-
config[:fetch] = Sidekiq::Throttled::Fetch.new(config)
|
60
|
-
end
|
61
|
-
end
|
53
|
+
Sidekiq::Throttled::Patches::BasicFetch.apply!
|
62
54
|
end
|
63
55
|
|
64
56
|
# Tells whenever job is throttled or not.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-throttled
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.alpha
|
4
|
+
version: 1.0.0.alpha.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Zapparov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-prescription
|
@@ -48,12 +48,11 @@ files:
|
|
48
48
|
- LICENSE
|
49
49
|
- README.adoc
|
50
50
|
- lib/sidekiq/throttled.rb
|
51
|
-
- lib/sidekiq/throttled/basic_fetch.rb
|
52
51
|
- lib/sidekiq/throttled/configuration.rb
|
53
52
|
- lib/sidekiq/throttled/errors.rb
|
54
|
-
- lib/sidekiq/throttled/fetch.rb
|
55
53
|
- lib/sidekiq/throttled/job.rb
|
56
54
|
- lib/sidekiq/throttled/middleware.rb
|
55
|
+
- lib/sidekiq/throttled/patches/basic_fetch.rb
|
57
56
|
- lib/sidekiq/throttled/registry.rb
|
58
57
|
- lib/sidekiq/throttled/strategy.rb
|
59
58
|
- lib/sidekiq/throttled/strategy/base.rb
|
@@ -72,9 +71,9 @@ licenses:
|
|
72
71
|
- MIT
|
73
72
|
metadata:
|
74
73
|
homepage_uri: https://github.com/ixti/sidekiq-throttled
|
75
|
-
source_code_uri: https://github.com/ixti/sidekiq-throttled/tree/v1.0.0.alpha
|
74
|
+
source_code_uri: https://github.com/ixti/sidekiq-throttled/tree/v1.0.0.alpha.1
|
76
75
|
bug_tracker_uri: https://github.com/ixti/sidekiq-throttled/issues
|
77
|
-
changelog_uri: https://github.com/ixti/sidekiq-throttled/blob/v1.0.0.alpha/CHANGES.md
|
76
|
+
changelog_uri: https://github.com/ixti/sidekiq-throttled/blob/v1.0.0.alpha.1/CHANGES.md
|
78
77
|
rubygems_mfa_required: 'true'
|
79
78
|
post_install_message:
|
80
79
|
rdoc_options: []
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "sidekiq"
|
4
|
-
require "sidekiq/fetch"
|
5
|
-
|
6
|
-
module Sidekiq
|
7
|
-
module Throttled
|
8
|
-
# Default Sidekiq's BasicFetch infused with Throttler.
|
9
|
-
#
|
10
|
-
# @private
|
11
|
-
class BasicFetch < Sidekiq::BasicFetch
|
12
|
-
# Retrieves job from redis.
|
13
|
-
#
|
14
|
-
# @return [Sidekiq::Throttled::UnitOfWork, nil]
|
15
|
-
def retrieve_work
|
16
|
-
work = super
|
17
|
-
|
18
|
-
if work && Throttled.throttled?(work.job)
|
19
|
-
requeue_throttled(work)
|
20
|
-
return nil
|
21
|
-
end
|
22
|
-
|
23
|
-
work
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
# Pushes job back to the head of the queue, so that job won't be tried
|
29
|
-
# immediately after it was requeued (in most cases).
|
30
|
-
#
|
31
|
-
# @note This is triggered when job is throttled. So it is same operation
|
32
|
-
# Sidekiq performs upon `Sidekiq::Worker.perform_async` call.
|
33
|
-
#
|
34
|
-
# @return [void]
|
35
|
-
def requeue_throttled(work)
|
36
|
-
redis { |conn| conn.lpush(work.queue, work.job) }
|
37
|
-
end
|
38
|
-
|
39
|
-
# Returns list of queues to try to fetch jobs from.
|
40
|
-
#
|
41
|
-
# @note It may return an empty array.
|
42
|
-
# @param [Array<String>] queues
|
43
|
-
# @return [Array<String>]
|
44
|
-
def queues_cmd
|
45
|
-
queues = super
|
46
|
-
|
47
|
-
# TODO: Refactor to be prepended as an integration mixin during configuration stage
|
48
|
-
# Or via configurable queues reducer
|
49
|
-
queues -= Sidekiq::Pauzer.paused_queues.map { |name| "queue:#{name}" } if defined?(Sidekiq::Pauzer)
|
50
|
-
|
51
|
-
queues
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|