sidekiq-throttled 1.0.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90f1a4d340b3475746da902b0a469af8269e39fc6953b8bb08e759c0600caf1e
4
- data.tar.gz: d03565985b3a0cca9d350a1b86c97530fc3b02bfef3773ecebe5ee7654ee8286
3
+ metadata.gz: 31c4673002a4919f71a18009e82812f21a777d241072bc095994e4a67662a49e
4
+ data.tar.gz: fa2c768c9ea4b023e16864c77eabe4949e9e3301a20aab5cdb5acdbdd3de9702
5
5
  SHA512:
6
- metadata.gz: 88770ec54943f0f455432de0e9455ef19877f5ddbf58821c3e8ee997afc0c0f3b7468010aa2fe4297c3f9069758e8e903e1a3243271afa454aff5575afcea071
7
- data.tar.gz: d1345ef48cb90f9174f71a9bc2625f5d1c2d218e5d1eb7d00f98c3014efbb0e83e3682ca8742baa960e17433da80267a8b716cad4a04b78716e96f9089fb01f3
6
+ metadata.gz: 636e41cc593e6f164061ff901ab6dab4eba7c65acf1bb41febbca13be55e9336bd86413ac50db80469429ff3bd8d9eaccd62b4e9f397a7692c184c7c70f0b98f
7
+ data.tar.gz: 7055289ad5e059da619ede7c4d9ec73876894dc4a3913851e55e256e81be9bb08c3671199c81eafaf6865fe50b0f60ad670fa2e74460de45c89b20af9514a90e
data/README.adoc CHANGED
@@ -44,12 +44,8 @@ you are using Rails):
44
44
  [source,ruby]
45
45
  ----
46
46
  require "sidekiq/throttled"
47
- Sidekiq::Throttled.setup!
48
47
  ----
49
48
 
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
49
  Once you've done that you can include `Sidekiq::Throttled::Job` to your
54
50
  job classes and configure throttling:
55
51
 
@@ -89,6 +85,27 @@ end
89
85
  ----
90
86
 
91
87
 
88
+ === Middleware(s)
89
+
90
+ `Sidekiq::Throttled` relies on following bundled middlewares:
91
+
92
+ * `Sidekiq::Throttled::Middlewares::Server`
93
+
94
+ The middleware is automatically injected when you require `sidekiq/throttled`.
95
+ In rare cases this might be an issue. You can change to order manually:
96
+
97
+ [source,ruby]
98
+ ----
99
+ Sidekiq.configure_server do |config|
100
+ # ...
101
+
102
+ config.server_middleware do |chain|
103
+ chain.remove(Sidekiq::Throttled::Middlewares::Server)
104
+ chain.add(Sidekiq::Throttled::Middlewares::Server)
105
+ end
106
+ end
107
+ ----
108
+
92
109
  === Configuration
93
110
 
94
111
  [source,ruby]
@@ -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
@@ -3,6 +3,6 @@
3
3
  module Sidekiq
4
4
  module Throttled
5
5
  # Gem version
6
- VERSION = "1.0.1"
6
+ VERSION = "1.1.0"
7
7
  end
8
8
  end
@@ -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/middleware"
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
@@ -97,6 +88,24 @@ module Sidekiq
97
88
  rescue
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.1
4
+ version: 1.1.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-20 00:00:00.000000000 Z
11
+ date: 2023-11-21 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/middleware.rb
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.1
90
+ source_code_uri: https://github.com/ixti/sidekiq-throttled/tree/v1.1.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.1/CHANGES.md
92
+ changelog_uri: https://github.com/ixti/sidekiq-throttled/blob/v1.1.0/CHANGES.md
93
93
  rubygems_mfa_required: 'true'
94
94
  post_install_message:
95
95
  rdoc_options: []
@@ -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
File without changes