sidekiq-throttled 1.0.1 → 1.2.0
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 +4 -4
- data/README.adoc +34 -9
- data/lib/sidekiq/throttled/middlewares/server.rb +28 -0
- data/lib/sidekiq/throttled/strategy/base.rb +1 -1
- data/lib/sidekiq/throttled/version.rb +1 -1
- data/lib/sidekiq/throttled.rb +20 -11
- metadata +8 -8
- data/lib/sidekiq/throttled/middleware.rb +0 -29
- /data/{LICENSE → LICENSE.txt} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a187d7a0ab7f55794f909da549082fb32ec06acca0e75928fa970fd2312a63e
|
4
|
+
data.tar.gz: c6acd8c1ebe40741e0285e6de82c0384b60a7a03ccee602b8de29309cb8bc313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f777dff16dc389b43a089c4e392228afc695830bea0bedb4a4aa4b04d49b44a0ae5b60d643a255548947f90eeb198aaf91219f9f282de29b8c7c009626e6e4f
|
7
|
+
data.tar.gz: 86b28f4fa073f7930254269e766576da4bf3412a262d9e0329285221b1376437dc6f072e9aa93be1402da7e06f3f5501ce416b241d134c666546ae3abb7397fe
|
data/README.adoc
CHANGED
@@ -12,11 +12,7 @@
|
|
12
12
|
{doc-link}[image:{doc-badge}[API Documentation]]
|
13
13
|
****
|
14
14
|
|
15
|
-
|
16
|
-
see: https://github.com/ixti/sidekiq-throttled/tree/0-x-stable[0-x-stable]
|
17
|
-
|
18
|
-
Concurrency and threshold throttling for https://github.com/mperham/sidekiq[Sidekiq].
|
19
|
-
|
15
|
+
Concurrency and threshold throttling for https://github.com/sidekiq/sidekiq[Sidekiq].
|
20
16
|
|
21
17
|
== Installation
|
22
18
|
|
@@ -44,12 +40,8 @@ you are using Rails):
|
|
44
40
|
[source,ruby]
|
45
41
|
----
|
46
42
|
require "sidekiq/throttled"
|
47
|
-
Sidekiq::Throttled.setup!
|
48
43
|
----
|
49
44
|
|
50
|
-
Load order can be an issue if you are using other Sidekiq plugins and/or middleware.
|
51
|
-
To prevent any problems, add the `.setup!` call to the bottom of your init file.
|
52
|
-
|
53
45
|
Once you've done that you can include `Sidekiq::Throttled::Job` to your
|
54
46
|
job classes and configure throttling:
|
55
47
|
|
@@ -108,6 +100,30 @@ end
|
|
108
100
|
----
|
109
101
|
|
110
102
|
|
103
|
+
==== Middleware(s)
|
104
|
+
|
105
|
+
`Sidekiq::Throttled` relies on following bundled middlewares:
|
106
|
+
|
107
|
+
* `Sidekiq::Throttled::Middlewares::Server`
|
108
|
+
|
109
|
+
The middleware is automatically injected when you require `sidekiq/throttled`.
|
110
|
+
In rare cases this might be an issue. You can change to order manually:
|
111
|
+
|
112
|
+
[source,ruby]
|
113
|
+
----
|
114
|
+
Sidekiq.configure_server do |config|
|
115
|
+
# ...
|
116
|
+
|
117
|
+
config.server_middleware do |chain|
|
118
|
+
chain.remove(Sidekiq::Throttled::Middlewares::Server)
|
119
|
+
chain.add(Sidekiq::Throttled::Middlewares::Server)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
----
|
123
|
+
|
124
|
+
See: https://github.com/sidekiq/sidekiq/blob/main/lib/sidekiq/middleware/chain.rb
|
125
|
+
|
126
|
+
|
111
127
|
=== Observer
|
112
128
|
|
113
129
|
You can specify an observer that will be called on throttling. To do so pass an
|
@@ -251,6 +267,7 @@ sidekiq_throttle(concurrency: { limit: 20, ttl: 1.hour.to_i })
|
|
251
267
|
|
252
268
|
This library aims to support and is tested against the following Ruby versions:
|
253
269
|
|
270
|
+
* Ruby 2.7.x
|
254
271
|
* Ruby 3.0.x
|
255
272
|
* Ruby 3.1.x
|
256
273
|
* Ruby 3.2.x
|
@@ -295,3 +312,11 @@ This library aims to support and work with following Sidekiq versions:
|
|
295
312
|
* Send a pull request
|
296
313
|
* If we like them we'll merge them
|
297
314
|
* If we've accepted a patch, feel free to ask for commit access!
|
315
|
+
|
316
|
+
|
317
|
+
== Endorsement
|
318
|
+
|
319
|
+
https://github.com/sensortower[image:sensortower.svg[SensorTower]]
|
320
|
+
|
321
|
+
The initial work on the project was initiated to address the needs of
|
322
|
+
https://github.com/sensortower[SensorTower].
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# internal
|
4
|
+
require_relative "../registry"
|
5
|
+
|
6
|
+
module Sidekiq
|
7
|
+
module Throttled
|
8
|
+
module Middlewares
|
9
|
+
# Server middleware required for Sidekiq::Throttled functioning.
|
10
|
+
class Server
|
11
|
+
include Sidekiq::ServerMiddleware
|
12
|
+
|
13
|
+
def call(_worker, msg, _queue)
|
14
|
+
yield
|
15
|
+
ensure
|
16
|
+
job = msg.fetch("wrapped") { msg["class"] }
|
17
|
+
jid = msg["jid"]
|
18
|
+
|
19
|
+
if job && jid
|
20
|
+
Registry.get job do |strategy|
|
21
|
+
strategy.finalize!(jid, *msg["args"])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/sidekiq/throttled.rb
CHANGED
@@ -5,7 +5,7 @@ require "sidekiq"
|
|
5
5
|
require_relative "./throttled/config"
|
6
6
|
require_relative "./throttled/cooldown"
|
7
7
|
require_relative "./throttled/job"
|
8
|
-
require_relative "./throttled/
|
8
|
+
require_relative "./throttled/middlewares/server"
|
9
9
|
require_relative "./throttled/patches/basic_fetch"
|
10
10
|
require_relative "./throttled/registry"
|
11
11
|
require_relative "./throttled/version"
|
@@ -18,7 +18,6 @@ module Sidekiq
|
|
18
18
|
# Just add somewhere in your bootstrap:
|
19
19
|
#
|
20
20
|
# require "sidekiq/throttled"
|
21
|
-
# Sidekiq::Throttled.setup!
|
22
21
|
#
|
23
22
|
# Once you've done that you can include {Sidekiq::Throttled::Job} to your
|
24
23
|
# job classes and configure throttling:
|
@@ -70,14 +69,6 @@ module Sidekiq
|
|
70
69
|
end
|
71
70
|
end
|
72
71
|
|
73
|
-
def setup!
|
74
|
-
Sidekiq.configure_server do |config|
|
75
|
-
config.server_middleware do |chain|
|
76
|
-
chain.add Sidekiq::Throttled::Middleware
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
72
|
# Tells whenever job is throttled or not.
|
82
73
|
#
|
83
74
|
# @param [String] message Job's JSON payload
|
@@ -94,9 +85,27 @@ module Sidekiq
|
|
94
85
|
end
|
95
86
|
|
96
87
|
false
|
97
|
-
rescue
|
88
|
+
rescue StandardError
|
98
89
|
false
|
99
90
|
end
|
91
|
+
|
92
|
+
# @deprecated Will be removed in 2.0.0
|
93
|
+
def setup!
|
94
|
+
warn "Sidekiq::Throttled.setup! was deprecated"
|
95
|
+
|
96
|
+
Sidekiq.configure_server do |config|
|
97
|
+
config.server_middleware do |chain|
|
98
|
+
chain.remove(Sidekiq::Throttled::Middlewares::Server)
|
99
|
+
chain.add(Sidekiq::Throttled::Middlewares::Server)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
configure_server do |config|
|
107
|
+
config.server_middleware do |chain|
|
108
|
+
chain.add(Sidekiq::Throttled::Middlewares::Server)
|
100
109
|
end
|
101
110
|
end
|
102
111
|
end
|
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
|
4
|
+
version: 1.2.0
|
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-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -59,7 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- LICENSE
|
62
|
+
- LICENSE.txt
|
63
63
|
- README.adoc
|
64
64
|
- lib/sidekiq/throttled.rb
|
65
65
|
- lib/sidekiq/throttled/config.rb
|
@@ -67,7 +67,7 @@ files:
|
|
67
67
|
- lib/sidekiq/throttled/errors.rb
|
68
68
|
- lib/sidekiq/throttled/expirable_set.rb
|
69
69
|
- lib/sidekiq/throttled/job.rb
|
70
|
-
- lib/sidekiq/throttled/
|
70
|
+
- lib/sidekiq/throttled/middlewares/server.rb
|
71
71
|
- lib/sidekiq/throttled/patches/basic_fetch.rb
|
72
72
|
- lib/sidekiq/throttled/registry.rb
|
73
73
|
- lib/sidekiq/throttled/strategy.rb
|
@@ -87,9 +87,9 @@ licenses:
|
|
87
87
|
- MIT
|
88
88
|
metadata:
|
89
89
|
homepage_uri: https://github.com/ixti/sidekiq-throttled
|
90
|
-
source_code_uri: https://github.com/ixti/sidekiq-throttled/tree/v1.0
|
90
|
+
source_code_uri: https://github.com/ixti/sidekiq-throttled/tree/v1.2.0
|
91
91
|
bug_tracker_uri: https://github.com/ixti/sidekiq-throttled/issues
|
92
|
-
changelog_uri: https://github.com/ixti/sidekiq-throttled/blob/v1.0
|
92
|
+
changelog_uri: https://github.com/ixti/sidekiq-throttled/blob/v1.2.0/CHANGES.md
|
93
93
|
rubygems_mfa_required: 'true'
|
94
94
|
post_install_message:
|
95
95
|
rdoc_options: []
|
@@ -99,14 +99,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
requirements:
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
102
|
+
version: '2.7'
|
103
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
105
|
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
109
|
+
rubygems_version: 3.3.26
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Concurrency and rate-limit throttling for Sidekiq
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# internal
|
4
|
-
require_relative "./registry"
|
5
|
-
|
6
|
-
module Sidekiq
|
7
|
-
module Throttled
|
8
|
-
# Server middleware that notifies strategy that job was finished.
|
9
|
-
#
|
10
|
-
# @private
|
11
|
-
class Middleware
|
12
|
-
include Sidekiq::ServerMiddleware
|
13
|
-
|
14
|
-
# Called within Sidekiq job processing
|
15
|
-
def call(_worker, msg, _queue)
|
16
|
-
yield
|
17
|
-
ensure
|
18
|
-
job = msg.fetch("wrapped") { msg["class"] }
|
19
|
-
jid = msg["jid"]
|
20
|
-
|
21
|
-
if job && jid
|
22
|
-
Registry.get job do |strategy|
|
23
|
-
strategy.finalize!(jid, *msg["args"])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
/data/{LICENSE → LICENSE.txt}
RENAMED
File without changes
|