pesto 0.0.9 → 0.0.10

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: ffdc583cb4fa5d4f90d988bd97fd6886e1ff73ef
4
- data.tar.gz: f9bd9ba9a341b286dccef5af3d516fff459f6e72
3
+ metadata.gz: 548db411d5cb5f639bc299add68aa29af743b2f3
4
+ data.tar.gz: 63a79d43327c3419a882e2faea5f5aadca73f6b0
5
5
  SHA512:
6
- metadata.gz: 82838a19298c2995c7c70c31d00c49b86c0be724baac794f5d06951fc8e49e14f7ce9ccbd0402aa97dd3addf9022d69369cc65a886a22a182c93b13bb968e6fa
7
- data.tar.gz: a75619382478f790f7f4eab8e981b66846900c26c7fbcbf715cd51dcbdec42668427fc199b65e870dc97a71a2ba054c7738b3fd3e29a6f65bc687191e21f1c37
6
+ metadata.gz: 70f9c0677b515a53aa0ca1b12b920a6ee1265240b701f9ebb5f8ed9fb9dce88250e0e96a3719e7ba3a680fdd93bcd8cc0be078f92546893646556033fea4db51
7
+ data.tar.gz: 15106012331ba282174c90108c7877e419d88f112f06ad1c172c3a2179abaff01f00a3d31a2fb0495de027d538e652a18ff7a9545ec902681e793de8a632e9ed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pesto (0.0.7)
4
+ pesto (0.0.10)
5
5
  connection_pool (~> 2.2)
6
6
  hiredis (~> 0.6)
7
7
  redis (~> 3.3)
@@ -49,7 +49,7 @@ for pid in 0..$concurrency
49
49
  redis = ConnectionPool.new(size: 5, :timeout => 10) { Redis.new(:driver => :hiredis) }
50
50
  while true do
51
51
  lock({ :pool => redis }, pfx, pid)
52
- if use_sweep
52
+ if $use_sleep
53
53
  delay = rand(1000).to_f / 10000.0
54
54
  sleep delay
55
55
  end
data/lib/pesto/lock.rb CHANGED
@@ -12,6 +12,28 @@ module Pesto
12
12
  :timeout_lock => 1,
13
13
  :interval_check => 0.05
14
14
  }.merge(opts)
15
+
16
+ load_scripts
17
+ end
18
+
19
+ def load_scripts
20
+ cp.with do |rc|
21
+ @script_sha = rc.script(
22
+ :load,
23
+ "local timeout = tonumber(ARGV[1])
24
+ assert(type(timeout) == 'number', 'timeout expects a number') \
25
+
26
+ if redis.call('setnx', KEYS[1], 1) == 1 then \
27
+ if tonumber(ARGV[1]) > -1 then \
28
+ redis.call('expire', KEYS[1], timeout) \
29
+ end
30
+ return 1 \
31
+ else \
32
+ return 0 \
33
+ end"
34
+ )
35
+ puts @script_sha
36
+ end
15
37
  end
16
38
 
17
39
  def conf
@@ -33,14 +55,14 @@ module Pesto
33
55
 
34
56
  names = (_names.is_a?(String) ? [_names] : _names).uniq
35
57
  opts[:timeout_lock_expire] = opts[:timeout_lock_expire].to_i
36
- opts[:timeout_lock_expire] += opts[:timeout_lock] * names.size
58
+ opts[:timeout_lock_expire] += (opts[:timeout_lock] * names.size).ceil.to_i
37
59
 
38
60
  t_start = Time.now
39
61
 
40
62
  while true
41
- res, locks, stop = get_locks names
42
-
43
- expire names, opts if stop && conf[:lock_expire]
63
+ res, locks, stop = get_locks names, {
64
+ :timeout_lock_expire => opts[:timeout_lock_expire]
65
+ }
44
66
 
45
67
  break if stop || (Time.now - t_start) > opts[:timeout_lock]
46
68
 
@@ -51,30 +73,25 @@ module Pesto
51
73
  stop ? 1 : 0
52
74
  end
53
75
 
54
- def expire names, opts={}
55
- cp.with do |rc|
56
- rc.pipelined do
57
- names.each do |n|
58
- rc.expire lock_hash(n), opts[:timeout_lock_expire].to_i
59
- end
60
- end
61
- end
62
- end
63
-
64
- def get_locks names
76
+ def get_locks names, opts = {}
65
77
  locked = 0
66
78
  locks = []
67
79
  res = []
68
80
 
81
+ timeout_lock_expire = conf[:lock_expire] ? opts[:timeout_lock_expire] : -1
82
+
69
83
  cp.with do |rc|
70
84
  res = rc.pipelined do
71
85
  names.each do |n|
72
- rc.setnx lock_hash(n), 1
86
+ rc.evalsha(@script_sha, {
87
+ :keys => [lock_hash(n)],
88
+ :argv => [timeout_lock_expire]
89
+ })
73
90
  end
74
91
  end
75
92
 
76
93
  names.each_with_index do |n, ix|
77
- next unless res[ix]
94
+ next if res[ix] != 1
78
95
  locked += 1
79
96
  locks.push n
80
97
  end
data/lib/pesto/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pesto
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pesto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - bfx devs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-21 00:00:00.000000000 Z
11
+ date: 2017-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hiredis