specwrk-store-redis_adapter 0.0.2 → 0.0.4
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 +4 -4
- data/docker-compose.yml +1 -1
- data/lib/specwrk/store/redis_adapter.rb +14 -34
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d04547dbffe8b9129a823f463c65ecf55a5e546d98df580f0b31cfa00be6e49
|
4
|
+
data.tar.gz: acdd63b88bd20fbd00630c672b8636576df932bb8a5e21556638628b4f4e7e6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a3a323c1d16651cbf4880e35deeae665db6df0aaf88d454a16417a6ea8f076dde4ee3a593a3fc4567e42421343ec313537dd4cc66baf35b6677a81642af8924
|
7
|
+
data.tar.gz: 7bc076bd89ae1993d58155efbec15b17130e2c689102d10e2b0ce670d61e752f46086b150aa2b6883bc019d1c886e2ac0b12edb5a210d8ecd26f39209bd94a7d
|
data/docker-compose.yml
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "json"
|
4
|
+
require "securerandom"
|
4
5
|
|
5
6
|
require "specwrk/store/base_adapter"
|
6
7
|
require "redis-client"
|
7
|
-
require "redlock"
|
8
8
|
|
9
9
|
module Specwrk
|
10
10
|
class Store
|
11
11
|
class RedisAdapter < Specwrk::Store::BaseAdapter
|
12
|
-
VERSION = "0.1.0"
|
13
|
-
|
14
12
|
REDIS_KEY_DELIMITER = "||||"
|
15
13
|
|
16
14
|
@connection_pools = {}
|
@@ -19,20 +17,22 @@ module Specwrk
|
|
19
17
|
class << self
|
20
18
|
def with_lock(uri, key)
|
21
19
|
connection_pool_for(uri).with do |connection|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
)
|
28
|
-
|
29
|
-
until (lock = client.lock("specwrk-lock-#{key}", lock_ttl))
|
30
|
-
sleep(rand(0.001..0.09))
|
20
|
+
id = SecureRandom.uuid
|
21
|
+
queue = "specwrk-lock-#{key}"
|
22
|
+
connection.pipelined do |pipeline|
|
23
|
+
pipeline.call("RPUSH", queue, id)
|
24
|
+
pipeline.call("EXPIRE", queue, 10) # only set if no expireat already
|
31
25
|
end
|
32
26
|
|
33
|
-
|
27
|
+
# wait for our id to be first in line or the queue to expire
|
28
|
+
sleep(rand(0.001..0.012)) until [id, nil].include? connection.call("LINDEX", queue, 0)
|
34
29
|
|
35
|
-
|
30
|
+
yield
|
31
|
+
ensure
|
32
|
+
connection.pipelined do |pipeline|
|
33
|
+
pipeline.call("LPOP", queue)
|
34
|
+
pipeline.call("EXPIRE", queue, 10) # keeps the queue fresh when things are moving
|
35
|
+
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -49,26 +49,6 @@ module Specwrk
|
|
49
49
|
def reset_connections!
|
50
50
|
@connection_pools.clear
|
51
51
|
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
# In ms
|
56
|
-
def lock_ttl
|
57
|
-
ENV.fetch("SPECWRK_REDIS_ADAPTER_LOCK_TTL", "5000").to_i
|
58
|
-
end
|
59
|
-
|
60
|
-
# See https://www.rubydoc.info/gems/redlock/Redlock/Client#initialize-instance_method
|
61
|
-
def lock_retry_count
|
62
|
-
ENV.fetch("SPECWRK_REDIS_ADAPTER_LOCK_RETRY_COUNT", "3").to_i
|
63
|
-
end
|
64
|
-
|
65
|
-
def lock_retry_delay
|
66
|
-
ENV.fetch("SPECWRK_REDIS_ADAPTER_LOCK_RETRY_DELAY", "100").to_i
|
67
|
-
end
|
68
|
-
|
69
|
-
def lock_retry_jitter
|
70
|
-
ENV.fetch("SPECWRK_REDIS_ADAPTER_LOCK_RETRY_JITTER", "10").to_i
|
71
|
-
end
|
72
52
|
end
|
73
53
|
|
74
54
|
def [](key)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: specwrk-store-redis_adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Westendorf
|
@@ -37,20 +37,6 @@ dependencies:
|
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
|
-
- !ruby/object:Gem::Dependency
|
41
|
-
name: redlock
|
42
|
-
requirement: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
47
|
-
type: :runtime
|
48
|
-
prerelease: false
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
40
|
- !ruby/object:Gem::Dependency
|
55
41
|
name: standard
|
56
42
|
requirement: !ruby/object:Gem::Requirement
|