syncrony 0.0.1 → 1.0.0
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 +13 -5
- data/Gemfile +0 -2
- data/lib/syncrony/election.rb +14 -8
- data/lib/syncrony/observer.rb +13 -8
- data/lib/syncrony/version.rb +1 -1
- data/syncrony.gemspec +1 -1
- metadata +26 -11
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MWUyYzkxMjg1Y2Q0ODNmZGQ2ZGUxYTY0ZWI5NTA5NGUwYmVhZTIwMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Yzk4NTBhZWU3NjgzOWNjMWRhMTIzYzc4MDZmNjU3YTMyNGJkOTlmMg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Mzg2MmI0ZWJmODhiYWY5NDA0Yzk5YWE4N2U5ZTZjMDkzOGE4YWZiNmNlYTA1
|
10
|
+
ZDU5MTA2YzIzYTNiMzQ4NTIyNzU1M2ZmNzQ0YzZjOTQ0MDgyMjYyMDU2OTk0
|
11
|
+
NjlkMWE5YjVlMDIyZTA2NzE3YjAwNzk5N2FmMjRiMTVmMDM3NjM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTFkMjM5ZjA2M2Y1MDZjOWNmNjFhZjAxMjE1NzlkYjY4MzI1MGEyNTBhODk0
|
14
|
+
MGE1YWFkZjE5OTJlZDhkMmM5ZTI4OWYzMTA2ZmE4YjI3OTE5ZmE2ZDYzOWFm
|
15
|
+
ZTI0MjJjMmM2MThjYzQ3ZDhlMmM2ZDJiZGFlYmQ3ZGExZjNlMTQ=
|
data/Gemfile
CHANGED
data/lib/syncrony/election.rb
CHANGED
@@ -10,23 +10,23 @@ module Syncrony
|
|
10
10
|
attr_accessor :is_leader
|
11
11
|
|
12
12
|
DEFAULT_OPTS = {
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
13
|
+
server: { host: '127.0.0.1', port: 4001 },
|
14
|
+
ttl: 15,
|
15
|
+
interval: 5
|
16
16
|
}
|
17
17
|
|
18
18
|
def initialize(options={})
|
19
19
|
options = DEFAULT_OPTS.merge(options)
|
20
20
|
raise if not options[:path]
|
21
21
|
@path = options[:path]
|
22
|
+
@server = options[:server]
|
22
23
|
@ttl = options[:ttl]
|
23
24
|
@interval = options[:interval]
|
24
25
|
@identifier = options[:identifier] || SecureRandom.uuid
|
25
26
|
end
|
26
27
|
|
27
28
|
def run
|
28
|
-
@client = Etcd
|
29
|
-
@client.connect
|
29
|
+
@client = Etcd.client(@server)
|
30
30
|
@is_leader = false
|
31
31
|
request_election
|
32
32
|
return
|
@@ -42,7 +42,6 @@ module Syncrony
|
|
42
42
|
# Stop being leader, or stop trying to become leader.
|
43
43
|
def cancel
|
44
44
|
@observer.cancel if @observer
|
45
|
-
# TODO race cdn here? Depends how Celluloid works. What if we're in the moddible of becoming leader?
|
46
45
|
if @is_leader
|
47
46
|
@timer.cancel
|
48
47
|
@is_leader = false
|
@@ -55,16 +54,23 @@ module Syncrony
|
|
55
54
|
@observer = Syncrony::Observer.new(@client, @path)
|
56
55
|
@observer.run do |value, path, info|
|
57
56
|
if value.nil?
|
58
|
-
|
57
|
+
begin
|
58
|
+
@client.set(@path, value: @identifier,
|
59
|
+
prevExist: false,
|
60
|
+
ttl: @ttl)
|
59
61
|
@observer.cancel
|
60
62
|
become_leader
|
63
|
+
rescue Etcd::TestFailed
|
64
|
+
# We lost the election race.
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
66
70
|
def update
|
67
|
-
@client.set(@path,
|
71
|
+
@client.set(@path, value: @identifier,
|
72
|
+
prevValue: @identifier,
|
73
|
+
ttl: @ttl)
|
68
74
|
end
|
69
75
|
|
70
76
|
end
|
data/lib/syncrony/observer.rb
CHANGED
@@ -13,18 +13,23 @@ module Syncrony
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def run(&handler)
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
begin
|
17
|
+
info = @client.get(@path)
|
18
|
+
value = info.value
|
19
|
+
index = info.etcd_index
|
20
|
+
rescue Etcd::KeyNotFound
|
21
|
+
info = nil
|
22
|
+
value = nil
|
23
|
+
index = nil
|
24
|
+
end
|
19
25
|
|
20
26
|
yield value, @path, info
|
21
27
|
|
22
28
|
while @running
|
23
|
-
@client.watch(@path, :index => index ? index + 1 : nil)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
29
|
+
watch = @client.watch(@path, :index => index ? index + 1 : nil)
|
30
|
+
if @running
|
31
|
+
index = watch.etcd_index
|
32
|
+
yield watch.value, @path, watch
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
data/lib/syncrony/version.rb
CHANGED
data/syncrony.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syncrony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Glanville
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,42 +28,56 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '>='
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - '>='
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - '>='
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - '>='
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: celluloid
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - '>='
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - '>='
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: etcd
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
description: Syncrony is a set of distributed systems primitives built with Celluloid
|
@@ -94,18 +108,19 @@ require_paths:
|
|
94
108
|
- lib
|
95
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
110
|
requirements:
|
97
|
-
- - '>='
|
111
|
+
- - ! '>='
|
98
112
|
- !ruby/object:Gem::Version
|
99
113
|
version: '0'
|
100
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
115
|
requirements:
|
102
|
-
- - '>='
|
116
|
+
- - ! '>='
|
103
117
|
- !ruby/object:Gem::Version
|
104
118
|
version: '0'
|
105
119
|
requirements: []
|
106
120
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.1.5
|
108
122
|
signing_key:
|
109
123
|
specification_version: 4
|
110
124
|
summary: Syncrony distributed systems toolkit
|
111
125
|
test_files: []
|
126
|
+
has_rdoc:
|