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 +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGES.md +7 -0
- data/lib/sidekiq/throttled/strategy/script.rb +33 -5
- data/lib/sidekiq/throttled/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77157db5b942df1a256b541b48cf882c0fb5fb9d
|
4
|
+
data.tar.gz: ec125a7c26dbe885913a7c0b0ef4f104f9f6bfb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d162a63285e5959673f6d497bc5f5d54726279c879f8835a46ff79bd249b71c36516fc119dc93391a772ccb046d4ce6b018cc60db813cd9c33daf56eb40006fd
|
7
|
+
data.tar.gz: d063e884b5d7bf613b64b53c14c410c2b64e995102a012363152ee907307d501f4af73fe5926828b3eaa3e3f17358cc78d46575cf343b662addfd6ea25d1ad6e
|
data/.rubocop.yml
CHANGED
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
|
-
|
34
|
+
# @paral [Logger] logger
|
35
|
+
def initialize(source, logger: Sidekiq.logger)
|
22
36
|
@source = source.to_s.strip.freeze
|
23
|
-
@
|
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(@
|
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
|
-
|
40
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2016-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|