travis-lock 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -3
- data/lib/travis/lock.rb +2 -2
- data/lib/travis/lock/postgresql.rb +5 -1
- data/lib/travis/lock/redis.rb +14 -5
- data/lib/travis/lock/support/retry.rb +1 -1
- data/lib/travis/lock/version.rb +1 -1
- data/spec/support/database.rb +9 -6
- data/spec/travis/lock/redis_spec.rb +2 -0
- data/travis-lock.gemspec +2 -4
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 438cbc91b63a790889bc58d8a5631f59ff394226
|
4
|
+
data.tar.gz: 9df4223ebb7224febae75e1248d075c3387a0b4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f671cffce832b81c01af24dd53859400434e105fdf4cf78f9e863b7b2cc83ca1801d05cfd9f9c8a0296368a72d1bd3a2e529c01396a6eceb9dd6d29af7bdb3ab
|
7
|
+
data.tar.gz: dfe0e317939a893bc77c9f4cec36ee571e0039826f79c25d48efb4e16392ebdc7218af74b72c18b5b77d911df7a404ecac717d3397ad744cfa02f4f0b2ac4c41
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
travis-lock (0.1.
|
5
|
-
activerecord (~> 4.0)
|
4
|
+
travis-lock (0.1.0)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
@@ -26,7 +25,7 @@ GEM
|
|
26
25
|
i18n (0.7.0)
|
27
26
|
json (1.8.3)
|
28
27
|
metaclass (0.0.4)
|
29
|
-
minitest (5.8.
|
28
|
+
minitest (5.8.1)
|
30
29
|
mocha (1.1.0)
|
31
30
|
metaclass (~> 0.0.1)
|
32
31
|
pg (0.18.3)
|
@@ -54,6 +53,7 @@ PLATFORMS
|
|
54
53
|
ruby
|
55
54
|
|
56
55
|
DEPENDENCIES
|
56
|
+
activerecord
|
57
57
|
mocha (~> 1.1)
|
58
58
|
pg
|
59
59
|
redlock
|
data/lib/travis/lock.rb
CHANGED
@@ -6,7 +6,7 @@ module Travis
|
|
6
6
|
module Lock
|
7
7
|
class Timeout < StandardError
|
8
8
|
def initialize(name, options)
|
9
|
-
super("Could not obtain lock for #{name}: #{options.map {
|
9
|
+
super("Could not obtain lock for #{name}: #{options.map { |pair| pair.join('=') }.join(' ')}")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -16,7 +16,7 @@ module Travis
|
|
16
16
|
|
17
17
|
def exclusive(name, options = {}, &block)
|
18
18
|
options[:strategy] ||= Lock.default_strategy || :none
|
19
|
-
const_get(camelize(options[:strategy])).new(name, options).exclusive(&block)
|
19
|
+
Lock.const_get(camelize(options[:strategy])).new(name, options).exclusive(&block)
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
@@ -3,8 +3,12 @@
|
|
3
3
|
# 13.3.4. Advisory Locks : http://www.postgresql.org/docs/9.3/static/explicit-locking.html
|
4
4
|
# http://www.postgresql.org/docs/9.3/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS
|
5
5
|
|
6
|
+
begin
|
7
|
+
require 'active_record'
|
8
|
+
rescue LoadError
|
9
|
+
end
|
10
|
+
|
6
11
|
require 'zlib'
|
7
|
-
require 'active_record'
|
8
12
|
require 'travis/lock/support/retry'
|
9
13
|
|
10
14
|
module Travis
|
data/lib/travis/lock/redis.rb
CHANGED
@@ -8,31 +8,38 @@ module Travis
|
|
8
8
|
module Lock
|
9
9
|
class Redis
|
10
10
|
class LockError < StandardError
|
11
|
+
attr_reader :key
|
12
|
+
|
11
13
|
def initialize(key)
|
14
|
+
@key = key
|
12
15
|
super("Could not obtain lock for #{key.inspect} on Redis.")
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
|
-
|
19
|
+
def self.clients
|
20
|
+
@clients ||= {}
|
21
|
+
end
|
17
22
|
|
18
23
|
DEFAULTS = {
|
19
24
|
ttl: 5 * 60,
|
20
25
|
retries: 5,
|
21
|
-
interval: 0.1
|
26
|
+
interval: 0.1,
|
27
|
+
timeout: 0.5
|
22
28
|
}
|
23
29
|
|
24
|
-
attr_reader :name, :config, :retried
|
30
|
+
attr_reader :name, :config, :retried, :monitor
|
25
31
|
|
26
32
|
def initialize(name, config)
|
27
33
|
@name = name
|
28
34
|
@config = DEFAULTS.merge(config)
|
29
35
|
@retried = 0
|
36
|
+
@monitor = Monitor.new
|
30
37
|
end
|
31
38
|
|
32
39
|
def exclusive
|
33
40
|
retrying do
|
34
41
|
client.lock(name, config[:ttl]) do |lock|
|
35
|
-
lock ? yield : raise(LockError.new(name))
|
42
|
+
lock ? yield(lock) : raise(LockError.new(name))
|
36
43
|
end
|
37
44
|
end
|
38
45
|
end
|
@@ -40,7 +47,9 @@ module Travis
|
|
40
47
|
private
|
41
48
|
|
42
49
|
def client
|
43
|
-
|
50
|
+
monitor.synchronize do
|
51
|
+
self.class.clients[url] ||= Redlock::Client.new([url], redis_timeout: config[:timeout])
|
52
|
+
end
|
44
53
|
end
|
45
54
|
|
46
55
|
def url
|
data/lib/travis/lock/version.rb
CHANGED
data/spec/support/database.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'active_record'
|
2
3
|
|
3
|
-
ActiveRecord::Base.establish_connection(
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
)
|
4
|
+
ActiveRecord::Base.establish_connection(
|
5
|
+
adapter: 'postgresql',
|
6
|
+
database: 'travis_test',
|
7
|
+
pool: 50
|
8
|
+
)
|
9
|
+
rescue LoadError
|
10
|
+
end
|
data/travis-lock.gemspec
CHANGED
@@ -9,14 +9,12 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ["Travis CI"]
|
10
10
|
s.email = "contact@travis-ci.org"
|
11
11
|
s.homepage = "https://github.com/travis-ci/travis-lock"
|
12
|
-
s.summary = "Travis CI
|
12
|
+
s.summary = "Locks for use at Travis CI"
|
13
13
|
s.description = "#{s.summary}."
|
14
|
-
s.
|
14
|
+
s.licenses = ["MIT"]
|
15
15
|
|
16
16
|
s.files = Dir['{lib/**/*,spec/**/*,[A-Z]*}']
|
17
17
|
s.platform = Gem::Platform::RUBY
|
18
18
|
s.require_path = 'lib'
|
19
19
|
s.rubyforge_project = '[none]'
|
20
|
-
|
21
|
-
s.add_dependency 'activerecord' , '~> 4.0'
|
22
20
|
end
|
metadata
CHANGED
@@ -1,30 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: travis-lock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis CI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
name: activerecord
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '4.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '4.0'
|
27
|
-
description: Travis CI config.
|
11
|
+
date: 2016-10-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Locks for use at Travis CI.
|
28
14
|
email: contact@travis-ci.org
|
29
15
|
executables: []
|
30
16
|
extensions: []
|
@@ -69,6 +55,6 @@ rubyforge_project: "[none]"
|
|
69
55
|
rubygems_version: 2.4.5
|
70
56
|
signing_key:
|
71
57
|
specification_version: 4
|
72
|
-
summary: Travis CI
|
58
|
+
summary: Locks for use at Travis CI
|
73
59
|
test_files: []
|
74
60
|
has_rdoc:
|