sidekiq-throttled 0.3.0 → 0.3.1

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
  SHA1:
3
- metadata.gz: 921d7e62de113744a3a0c9a6f7a1d6f028597349
4
- data.tar.gz: 68c41f87d3174e5bee4f32f74e6bf8f3b1cc1e57
3
+ metadata.gz: 77157db5b942df1a256b541b48cf882c0fb5fb9d
4
+ data.tar.gz: ec125a7c26dbe885913a7c0b0ef4f104f9f6bfb5
5
5
  SHA512:
6
- metadata.gz: f7080abc6b8ba73a1472a47c855973dcefccd610ccff81959719919f5e12ce47890b43d1ae9d8efe4e878b3f94a052eee35c864f7a735bd7317b9f1ad7507559
7
- data.tar.gz: 1b5c82fb79e87e4e040c729bcfdd15c98177d210af174096c846e8e7b19f17c3576069e1bde3130594c6f87c6fd1648192fb122f287bf4d1b94fb104c364a3fd
6
+ metadata.gz: d162a63285e5959673f6d497bc5f5d54726279c879f8835a46ff79bd249b71c36516fc119dc93391a772ccb046d4ce6b018cc60db813cd9c33daf56eb40006fd
7
+ data.tar.gz: d063e884b5d7bf613b64b53c14c410c2b64e995102a012363152ee907307d501f4af73fe5926828b3eaa3e3f17358cc78d46575cf343b662addfd6ea25d1ad6e
data/.rubocop.yml CHANGED
@@ -15,6 +15,9 @@ Style/BracesAroundHashParameters:
15
15
  Style/Documentation:
16
16
  Enabled: false
17
17
 
18
+ Style/EmptyCaseCondition:
19
+ Enabled: false
20
+
18
21
  Style/EmptyLineBetweenDefs:
19
22
  AllowAdjacentOneLineDefs: true
20
23
 
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.3.1 (2016-05-15)
2
+
3
+ * Precalculate LUA script digests to reduce bandwidth upon nodes reload
4
+ _(which might (and might not) happen if you run thousands of nodes)_.
5
+ ([@ixti])
6
+
7
+
1
8
  ## 0.3.0 (2016-05-02)
2
9
 
3
10
  * [#1](https://github.com/sensortower/sidekiq-throttled/issues/1):
@@ -1,4 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
3
+ require "digest/sha1"
4
+
5
+ require "sidekiq"
6
+
2
7
  module Sidekiq
3
8
  module Throttled
4
9
  class Strategy
@@ -17,15 +22,25 @@ module Sidekiq
17
22
  NOSCRIPT = "NOSCRIPT".freeze
18
23
  private_constant :NOSCRIPT
19
24
 
25
+ # LUA script source.
26
+ # @return [String]
27
+ attr_reader :source
28
+
29
+ # LUA script SHA1 digest.
30
+ # @return [String]
31
+ attr_reader :digest
32
+
20
33
  # @param [#to_s] source Lua script
21
- def initialize(source)
34
+ # @paral [Logger] logger
35
+ def initialize(source, logger: Sidekiq.logger)
22
36
  @source = source.to_s.strip.freeze
23
- @sha = nil
37
+ @digest = Digest::SHA1.hexdigest(@source).freeze
38
+ @logger = logger
24
39
  end
25
40
 
26
41
  # Executes script and returns result of execution
27
42
  def eval(*args)
28
- Sidekiq.redis { |conn| conn.evalsha(@sha, *args) }
43
+ Sidekiq.redis { |conn| conn.evalsha(@digest, *args) }
29
44
  rescue => e
30
45
  raise unless e.message.include? NOSCRIPT
31
46
  load_and_eval(*args)
@@ -36,8 +51,21 @@ module Sidekiq
36
51
  # Loads script into redis cache and executes it.
37
52
  def load_and_eval(*args)
38
53
  Sidekiq.redis do |conn|
39
- @sha = conn.script(LOAD, @source)
40
- conn.evalsha(@sha, *args)
54
+ digest = conn.script(LOAD, @source)
55
+
56
+ # XXX: this may happen **ONLY** if script digesting will be
57
+ # changed in redis, which is not likely gonna happen.
58
+ unless @digest == digest
59
+ if @logger
60
+ @logger.warn \
61
+ "Unexpected script SHA1 digest: " \
62
+ "#{digest.inspect} (expected: #{@digest.inspect})"
63
+ end
64
+
65
+ @digest = digest.freeze
66
+ end
67
+
68
+ conn.evalsha(@digest, *args)
41
69
  end
42
70
  end
43
71
  end
@@ -2,6 +2,6 @@
2
2
  module Sidekiq
3
3
  module Throttled
4
4
  # Gem version
5
- VERSION = "0.3.0".freeze
5
+ VERSION = "0.3.1".freeze
6
6
  end
7
7
  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.3.0
4
+ version: 0.3.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: 2016-05-02 00:00:00.000000000 Z
11
+ date: 2016-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq