sidekiq-throttled 0.8.0 → 0.8.1

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
  SHA1:
3
- metadata.gz: 3e18c53412711982bb7d620c5300d30d89cf1668
4
- data.tar.gz: abe45ca2b495ee939a8ce11437b9e1fc48664242
3
+ metadata.gz: 8ef8cce2c35072fd109e89066e293074fb125828
4
+ data.tar.gz: 575ea548b4594445fd8b2532896bac87149e96ef
5
5
  SHA512:
6
- metadata.gz: e8d86da7c4b388b3b235caff8a887e342cae176d42398ef4033d946532cb6bd4568080db5b1afca15b6f6efe4984dd124229219c73524cb5bfe58ee813461fcb
7
- data.tar.gz: 83e7c860e3b17b7ec8b4295ea6ddf5d6c9e8f9e984c4fa367d9d803cf2b7403e0bbafc0772df7b679e3e7ad0edfb47729646691eb913b10ff834c424aad97253
6
+ metadata.gz: 4f5b3b2b3023f776b247e07db7959ad691990d6dbddf26c662e101b95868440dea2c3f2c81f9ed139b5b471bfdc259b6a52649957f5bd809ec508b2f53fc7488
7
+ data.tar.gz: 5a898501386292385f3399ce572ea47110766e72c38dbf9ab5f57f23bca155c66c2e32cdb0c4b9adf31155b48382e96ca4a071294325cec3fc3beaa66ae9178b
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.8.1 (2017-11-02)
2
+
3
+ * Preload job class constant prior trying to get it's throttling strategy.
4
+ ([@ixti])
5
+
6
+
1
7
  ## 0.8.0 (2017-10-11)
2
8
 
3
9
  * Refactor concurrency throttling internals to use sorted sets in order to avoid
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # stdlib
4
+ require "thread"
5
+
3
6
  # 3rd party
4
7
  require "sidekiq"
5
8
 
@@ -40,6 +43,9 @@ module Sidekiq
40
43
  # end
41
44
  # end
42
45
  module Throttled
46
+ MUTEX = Mutex.new
47
+ private_constant :MUTEX
48
+
43
49
  class << self
44
50
  # Hooks throttler into sidekiq.
45
51
  #
@@ -68,6 +74,8 @@ module Sidekiq
68
74
  job = message.fetch("class") { return false }
69
75
  jid = message.fetch("jid") { return false }
70
76
 
77
+ preload_constant! job
78
+
71
79
  Registry.get job do |strategy|
72
80
  return strategy.throttled?(jid, *message["args"])
73
81
  end
@@ -76,6 +84,34 @@ module Sidekiq
76
84
  rescue
77
85
  false
78
86
  end
87
+
88
+ private
89
+
90
+ # Tries to preload constant by it's name once.
91
+ #
92
+ # Somehow, sometimes, some classes are not eager loaded upon Rails init,
93
+ # leading to throttling config not being registered prior job perform.
94
+ # And that leaves us with concurrency limit + 1 situation upon Sidekiq
95
+ # server restart (becomes normal after all Sidekiq processes handled
96
+ # at leas onr job of that class).
97
+ #
98
+ # @return [void]
99
+ def preload_constant!(job)
100
+ MUTEX.synchronize do
101
+ @preloaded ||= {}
102
+ @preloaded[job] ||= constantize(job) || true
103
+ end
104
+ end
105
+
106
+ # Resolve constant from it's name
107
+ def constantize(str)
108
+ str.sub(/^::/, "").split("::").inject(Object) do |const, name|
109
+ const.const_get(name)
110
+ end
111
+ rescue
112
+ Sidekiq.logger.warn { "Failed to constantize: #{str}" }
113
+ nil
114
+ end
79
115
  end
80
116
  end
81
117
  end
@@ -3,6 +3,6 @@
3
3
  module Sidekiq
4
4
  module Throttled
5
5
  # Gem version
6
- VERSION = "0.8.0"
6
+ VERSION = "0.8.1"
7
7
  end
8
8
  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: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey V Zapparov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-11 00:00:00.000000000 Z
11
+ date: 2017-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq