sidekiq-throttled 1.3.0 → 1.4.0

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: 433460cfaea479faf45edc665c6f8d7d025b3e35ccdf18a32061a0b3d3c42e68
4
- data.tar.gz: 4e36f4c938d7145646e04f1de6d483bdec5a4c18254c3153be3556285b779fbf
3
+ metadata.gz: 7746a966e9feb8f571468c3f9f790b618faacdb6a6b405183acce7afc9210fb0
4
+ data.tar.gz: 7b4a320e9ed8bab632e7834f67015b6b377071c77ac0838cf2a2db662c34ec81
5
5
  SHA512:
6
- metadata.gz: 3ba640f6b15fa32eb21eccda8a319357439b7367fea6c0e4d4125e0e2cd5e91fbb822768d2171c57ac0cfbe0ba640b1d21960c6e2ea317997869c8f06187aec9
7
- data.tar.gz: bd28f31c6222b3f378e1e7a2d081cc9f05c4feb13b7be8b1b54ee91976a66b2263884837f3149dddcc6b047129a0311b65135433511b0dc3ed29d47ed88346ea
6
+ metadata.gz: ed36a36f934b607f08c132db2296a02741d4fad2a4436f4c475bc66f6a0cda49ece9e95782092603e4a3146de4c9b4dc7eec95223d4ba15a3c92715d861a2c91
7
+ data.tar.gz: c99428f6499ddcc70d89c9b73c8dcbcae275a6a81533645dcc7d8d0d0a7f04492b876afb4d651a934e5df2ad82996925b1f551ff16a9309beba99a146c0726f9
data/README.adoc CHANGED
@@ -310,9 +310,9 @@ And the following Sidekiq Pro versions:
310
310
 
311
311
  === Sidekiq-Pro
312
312
 
313
- If you're working on Sidekiq-Pro support make sure to copy `.rspec-sidekiq-pro`
314
- to `.rspec-local` and that you have Sidekiq-Pro license in the global config,
315
- or in the `BUNDLE_GEMS\__CONTRIBSYS__COM` env variable.
313
+ If you're working on Sidekiq-Pro support make sure that you have Sidekiq-Pro
314
+ license set either in the global config, or in `BUNDLE_GEMS\__CONTRIBSYS__COM`
315
+ environment variable.
316
316
 
317
317
  == Contributing
318
318
 
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sidekiq
4
+ module Throttled
5
+ class Message
6
+ def initialize(item)
7
+ @item = item.is_a?(Hash) ? item : parse(item)
8
+ end
9
+
10
+ def job_class
11
+ @item.fetch("wrapped") { @item["class"] }
12
+ end
13
+
14
+ def job_args
15
+ @item.key?("wrapped") ? @item.dig("args", 0, "arguments") : @item["args"]
16
+ end
17
+
18
+ def job_id
19
+ @item["jid"]
20
+ end
21
+
22
+ private
23
+
24
+ def parse(item)
25
+ item = Sidekiq.load_json(item)
26
+ item.is_a?(Hash) ? item : {}
27
+ rescue JSON::ParserError
28
+ {}
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # internal
4
+ require_relative "../message"
4
5
  require_relative "../registry"
5
6
 
6
7
  module Sidekiq
@@ -13,12 +14,11 @@ module Sidekiq
13
14
  def call(_worker, msg, _queue)
14
15
  yield
15
16
  ensure
16
- job = msg.fetch("wrapped") { msg["class"] }
17
- jid = msg["jid"]
17
+ message = Message.new(msg)
18
18
 
19
- if job && jid
20
- Registry.get job do |strategy|
21
- strategy.finalize!(jid, *msg["args"])
19
+ if message.job_class && message.job_id
20
+ Registry.get(message.job_class) do |strategy|
21
+ strategy.finalize!(message.job_id, *message.job_args)
22
22
  end
23
23
  end
24
24
  end
@@ -3,6 +3,6 @@
3
3
  module Sidekiq
4
4
  module Throttled
5
5
  # Gem version
6
- VERSION = "1.3.0"
6
+ VERSION = "1.4.0"
7
7
  end
8
8
  end
@@ -5,6 +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/message"
8
9
  require_relative "./throttled/middlewares/server"
9
10
  require_relative "./throttled/patches/basic_fetch"
10
11
  require_relative "./throttled/patches/super_fetch"
@@ -75,14 +76,11 @@ module Sidekiq
75
76
  # @param [String] message Job's JSON payload
76
77
  # @return [Boolean]
77
78
  def throttled?(message)
78
- message = Sidekiq.load_json(message)
79
- job = message.fetch("wrapped") { message["class"] }
80
- jid = message["jid"]
79
+ message = Message.new(message)
80
+ return false unless message.job_class && message.job_id
81
81
 
82
- return false unless job && jid
83
-
84
- Registry.get(job) do |strategy|
85
- return strategy.throttled?(jid, *message["args"])
82
+ Registry.get(message.job_class) do |strategy|
83
+ return strategy.throttled?(message.job_id, *message.job_args)
86
84
  end
87
85
 
88
86
  false
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.3.0
4
+ version: 1.4.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: 2024-01-18 00:00:00.000000000 Z
11
+ date: 2024-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -67,6 +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/message.rb
70
71
  - lib/sidekiq/throttled/middlewares/server.rb
71
72
  - lib/sidekiq/throttled/patches/basic_fetch.rb
72
73
  - lib/sidekiq/throttled/patches/super_fetch.rb
@@ -89,9 +90,9 @@ licenses:
89
90
  - MIT
90
91
  metadata:
91
92
  homepage_uri: https://github.com/ixti/sidekiq-throttled
92
- source_code_uri: https://github.com/ixti/sidekiq-throttled/tree/v1.3.0
93
+ source_code_uri: https://github.com/ixti/sidekiq-throttled/tree/v1.4.0
93
94
  bug_tracker_uri: https://github.com/ixti/sidekiq-throttled/issues
94
- changelog_uri: https://github.com/ixti/sidekiq-throttled/blob/v1.3.0/CHANGES.md
95
+ changelog_uri: https://github.com/ixti/sidekiq-throttled/blob/v1.4.0/CHANGES.md
95
96
  rubygems_mfa_required: 'true'
96
97
  post_install_message:
97
98
  rdoc_options: []