cloudtasker 0.10.rc4 → 0.10.rc5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cloudtasker.gemspec +1 -0
- data/lib/cloudtasker/redis_client.rb +27 -12
- data/lib/cloudtasker/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db7ce2488df7c451c0ed08a2674c32e6e5964a926ad8bf158fee3e76ec71ee82
|
4
|
+
data.tar.gz: 354177692074ddf3aa74fb1dba70dd56933211b460f035884fbf34bc87dc89fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 627dc29f6318bc4f0f676deea5ea932f6ec6414cf7f98c3f986132de59c44d30db5d645c518a04bf98ca99925719efce7a430a48a85d83be1cd90551a5f8206a
|
7
|
+
data.tar.gz: e9806327d16e5ac6700577732cc9347f403eb21c6debd52cbacb36157af110a3ccab917e01fab9d6cd87d98ae0cfa1558fe7ebf0d1a938d4a0b40a13a492e87d
|
data/cloudtasker.gemspec
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'redis'
|
4
|
+
require 'connection_pool'
|
4
5
|
|
5
6
|
module Cloudtasker
|
6
7
|
# A wrapper with helper methods for redis
|
@@ -10,8 +11,18 @@ module Cloudtasker
|
|
10
11
|
LOCK_DURATION = 2 # seconds
|
11
12
|
LOCK_WAIT_DURATION = 0.03 # seconds
|
12
13
|
|
14
|
+
# Default pool size used for Redis
|
15
|
+
DEFAULT_POOL_SIZE = ENV.fetch('RAILS_MAX_THREADS') { 25 }
|
16
|
+
DEFAULT_POOL_TIMEOUT = 5
|
17
|
+
|
13
18
|
def self.client
|
14
|
-
@client ||=
|
19
|
+
@client ||= begin
|
20
|
+
pool_size = Cloudtasker.config.redis&.dig(:pool_size) || DEFAULT_POOL_SIZE
|
21
|
+
pool_timeout = Cloudtasker.config.redis&.dig(:pool_timeout) || DEFAULT_POOL_TIMEOUT
|
22
|
+
ConnectionPool.new(size: pool_size, timeout: pool_timeout) do
|
23
|
+
Redis.new(Cloudtasker.config.redis || {})
|
24
|
+
end
|
25
|
+
end
|
15
26
|
end
|
16
27
|
|
17
28
|
#
|
@@ -31,7 +42,7 @@ module Cloudtasker
|
|
31
42
|
# @return [Hash, Array] The content of the cache key, parsed as JSON.
|
32
43
|
#
|
33
44
|
def fetch(key)
|
34
|
-
return nil unless (val =
|
45
|
+
return nil unless (val = get(key.to_s))
|
35
46
|
|
36
47
|
JSON.parse(val, symbolize_names: true)
|
37
48
|
rescue JSON::ParserError
|
@@ -47,7 +58,7 @@ module Cloudtasker
|
|
47
58
|
# @return [String] Redis response code.
|
48
59
|
#
|
49
60
|
def write(key, content)
|
50
|
-
|
61
|
+
set(key.to_s, content.to_json)
|
51
62
|
end
|
52
63
|
|
53
64
|
#
|
@@ -70,12 +81,14 @@ module Cloudtasker
|
|
70
81
|
|
71
82
|
# Wait to acquire lock
|
72
83
|
lock_key = [LOCK_KEY_PREFIX, cache_key].join('/')
|
73
|
-
|
84
|
+
client.with do |conn|
|
85
|
+
sleep(LOCK_WAIT_DURATION) until conn.set(lock_key, true, nx: true, ex: LOCK_DURATION)
|
86
|
+
end
|
74
87
|
|
75
88
|
# yield content
|
76
89
|
yield
|
77
90
|
ensure
|
78
|
-
|
91
|
+
del(lock_key)
|
79
92
|
end
|
80
93
|
|
81
94
|
#
|
@@ -104,10 +117,12 @@ module Cloudtasker
|
|
104
117
|
list = []
|
105
118
|
|
106
119
|
# Scan and capture matching keys
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
120
|
+
client.with do |conn|
|
121
|
+
while cursor != 0
|
122
|
+
scan = conn.scan(cursor || 0, match: pattern)
|
123
|
+
list += scan[1]
|
124
|
+
cursor = scan[0].to_i
|
125
|
+
end
|
111
126
|
end
|
112
127
|
|
113
128
|
list
|
@@ -123,8 +138,8 @@ module Cloudtasker
|
|
123
138
|
# @return [Any] The method return value
|
124
139
|
#
|
125
140
|
def method_missing(name, *args, &block)
|
126
|
-
if
|
127
|
-
client.send(name, *args, &block)
|
141
|
+
if Redis.method_defined?(name)
|
142
|
+
client.with { |c| c.send(name, *args, &block) }
|
128
143
|
else
|
129
144
|
super
|
130
145
|
end
|
@@ -139,7 +154,7 @@ module Cloudtasker
|
|
139
154
|
# @return [Boolean] Return true if the class respond to this method.
|
140
155
|
#
|
141
156
|
def respond_to_missing?(name, include_private = false)
|
142
|
-
|
157
|
+
Redis.method_defined?(name) || super
|
143
158
|
end
|
144
159
|
end
|
145
160
|
end
|
data/lib/cloudtasker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudtasker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.rc5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Lachaume
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: connection_pool
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: fugit
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|