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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 228f7fc8ef7ca52a1a9827b233ae1ebfea77e2a6d6683d68caa3fffef697ffb4
4
- data.tar.gz: b58fee4392d02847c462684744a5b90ff413564a02e3e74b51514b7f8aee4107
3
+ metadata.gz: db7ce2488df7c451c0ed08a2674c32e6e5964a926ad8bf158fee3e76ec71ee82
4
+ data.tar.gz: 354177692074ddf3aa74fb1dba70dd56933211b460f035884fbf34bc87dc89fc
5
5
  SHA512:
6
- metadata.gz: 88d7bfd9d4bbdb38ca48cf5e3af1fd9f901a3f89b84bce7d41609baa22d7ded5ce0c3a657d8aaaa9ad3b9274ad389825bdd7e17272f65ef80a68c6cb96538d25
7
- data.tar.gz: b0a1f08dd892a9c709ecb24fb9a38c6507489179ce06779e49c9641d1ed849b02af6c3717476d85e7cf852879d0a5c8429123bc843a4ce60933f8319d0241e5a
6
+ metadata.gz: 627dc29f6318bc4f0f676deea5ea932f6ec6414cf7f98c3f986132de59c44d30db5d645c518a04bf98ca99925719efce7a430a48a85d83be1cd90551a5f8206a
7
+ data.tar.gz: e9806327d16e5ac6700577732cc9347f403eb21c6debd52cbacb36157af110a3ccab917e01fab9d6cd87d98ae0cfa1558fe7ebf0d1a938d4a0b40a13a492e87d
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ['lib']
32
32
 
33
33
  spec.add_dependency 'activesupport'
34
+ spec.add_dependency 'connection_pool'
34
35
  spec.add_dependency 'fugit'
35
36
  spec.add_dependency 'google-cloud-tasks'
36
37
  spec.add_dependency 'jwt'
@@ -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 ||= Redis.new(Cloudtasker.config.redis || {})
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 = client.get(key.to_s))
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
- client.set(key.to_s, content.to_json)
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
- sleep(LOCK_WAIT_DURATION) until client.set(lock_key, true, nx: true, ex: LOCK_DURATION)
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
- client.del(lock_key)
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
- while cursor != 0
108
- scan = client.scan(cursor || 0, match: pattern)
109
- list += scan[1]
110
- cursor = scan[0].to_i
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 client.respond_to?(name)
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
- client.respond_to?(name) || super
157
+ Redis.method_defined?(name) || super
143
158
  end
144
159
  end
145
160
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudtasker
4
- VERSION = '0.10.rc4'
4
+ VERSION = '0.10.rc5'
5
5
  end
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.rc4
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-02 00:00:00.000000000 Z
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