diplomat 0.8.4 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/diplomat/event.rb +19 -8
- data/lib/diplomat/kv.rb +6 -1
- data/lib/diplomat/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88a912b85c1348113d9b8e5f941bb652295dbac8
|
4
|
+
data.tar.gz: 64c21697ea68210e172293afc90b0bc894a238cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e17459f8b810a4213ffa6a1e87aa4e4a91391f289c954526ed06a4601a754d9e3d230d5666bf9b5775f053627258a45dd163d1cb327f27424588e08c959d1b95
|
7
|
+
data.tar.gz: 0b0300f116e79dafb2fd26a2b123962e0ccecfabb7733dfacf034f9ee69b15c728f3da15a07a1974a17591fb0cc5237da60e8ffa176594310d3c252134c57945
|
data/lib/diplomat/event.rb
CHANGED
@@ -26,7 +26,7 @@ module Diplomat
|
|
26
26
|
# Get the list of events matching name
|
27
27
|
# @param name [String] the name of the event (regex)
|
28
28
|
# @param not_found [Symbol] behaviour if there are no events matching name;
|
29
|
-
# :reject with exception, or :wait for a non-empty list
|
29
|
+
# :reject with exception, :return degenerate value, or :wait for a non-empty list
|
30
30
|
# @param found [Symbol] behaviour if there are already events matching name;
|
31
31
|
# :reject with exception, :return its current value, or :wait for its next value
|
32
32
|
# @return [Array[hash]] The list of { :name, :payload } hashes
|
@@ -46,6 +46,9 @@ module Diplomat
|
|
46
46
|
# - X X - meaningless; never return a value
|
47
47
|
# - X R - "normal" non-blocking get operation. Default
|
48
48
|
# - X W - get the next value only (must have a current value)
|
49
|
+
# - R X - meaningless; never return a meaningful value
|
50
|
+
# - R R - "safe" non-blocking, non-throwing get-or-default operation
|
51
|
+
# - R W - get the next value or a default
|
49
52
|
# - W X - get the first value only (must not have a current value)
|
50
53
|
# - W R - get the first or current value; always return something, but
|
51
54
|
# block only when necessary
|
@@ -61,6 +64,8 @@ module Diplomat
|
|
61
64
|
case not_found
|
62
65
|
when :reject
|
63
66
|
raise Diplomat::EventNotFound, name
|
67
|
+
when :return
|
68
|
+
return []
|
64
69
|
end
|
65
70
|
else
|
66
71
|
case found
|
@@ -83,7 +88,7 @@ module Diplomat
|
|
83
88
|
# String are tokens returned by previous calls to this function
|
84
89
|
# Symbols are the special tokens :first, :last, and :next
|
85
90
|
# @param not_found [Symbol] behaviour if there is no matching event;
|
86
|
-
# :reject with exception, or :wait for event
|
91
|
+
# :reject with exception, :return degenerate value, or :wait for event
|
87
92
|
# @param found [Symbol] behaviour if there is a matching event;
|
88
93
|
# :reject with exception, or :return its current value
|
89
94
|
# @return [hash] A hash with keys :value and :token;
|
@@ -114,12 +119,19 @@ module Diplomat
|
|
114
119
|
case not_found
|
115
120
|
when :reject
|
116
121
|
raise Diplomat::EventNotFound, name
|
122
|
+
when :return
|
123
|
+
event_name = ""
|
124
|
+
event_payload = ""
|
125
|
+
event_token = :last
|
117
126
|
when :wait
|
118
127
|
@raw = wait_for_next_event(url)
|
119
128
|
parse_body
|
120
129
|
# If it's possible for two events to arrive at once,
|
121
130
|
# this needs to #find again:
|
122
131
|
event = @raw.last
|
132
|
+
event_name = event["Name"]
|
133
|
+
event_payload = Base64.decode64(event["Payload"])
|
134
|
+
event_token = event["ID"]
|
123
135
|
end
|
124
136
|
else
|
125
137
|
case found
|
@@ -127,17 +139,16 @@ module Diplomat
|
|
127
139
|
raise Diplomat::EventAlreadyExits, name
|
128
140
|
when :return
|
129
141
|
event = body[idx]
|
142
|
+
event_name = event["Name"]
|
143
|
+
event_payload = Base64.decode64(event["Payload"])
|
144
|
+
event_token = event["ID"]
|
130
145
|
end
|
131
146
|
end
|
132
147
|
|
133
148
|
{
|
134
|
-
:value => {
|
135
|
-
|
136
|
-
:payload => Base64.decode64(event["Payload"])
|
137
|
-
},
|
138
|
-
:token => event["ID"]
|
149
|
+
:value => { :name => event_name, :payload => event_payload },
|
150
|
+
:token => event_token
|
139
151
|
}
|
140
|
-
|
141
152
|
end
|
142
153
|
|
143
154
|
|
data/lib/diplomat/kv.rb
CHANGED
@@ -11,7 +11,7 @@ module Diplomat
|
|
11
11
|
# @param options [Hash] the query params
|
12
12
|
# @option options [String] :consistency The read consistency type
|
13
13
|
# @param not_found [Symbol] behaviour if the key doesn't exist;
|
14
|
-
# :reject with exception, or :wait for it to appear
|
14
|
+
# :reject with exception, :return degenerate value, or :wait for it to appear
|
15
15
|
# @param found [Symbol] behaviour if the key does exist;
|
16
16
|
# :reject with exception, :return its current value, or :wait for its next value
|
17
17
|
# @return [String] The base64-decoded value associated with the key
|
@@ -24,6 +24,9 @@ module Diplomat
|
|
24
24
|
# - X X - meaningless; never return a value
|
25
25
|
# - X R - "normal" non-blocking get operation. Default
|
26
26
|
# - X W - get the next value only (must have a current value)
|
27
|
+
# - R X - meaningless; never return a meaningful value
|
28
|
+
# - R R - "safe" non-blocking, non-throwing get-or-default operation
|
29
|
+
# - R W - get the next value or a default
|
27
30
|
# - W X - get the first value only (must not have a current value)
|
28
31
|
# - W R - get the first or current value; always return something, but
|
29
32
|
# block only when necessary
|
@@ -42,6 +45,8 @@ module Diplomat
|
|
42
45
|
case not_found
|
43
46
|
when :reject
|
44
47
|
raise Diplomat::KeyNotFound, key
|
48
|
+
when :return
|
49
|
+
return @value = ""
|
45
50
|
when :wait
|
46
51
|
index = raw.headers["x-consul-index"]
|
47
52
|
end
|
data/lib/diplomat/version.rb
CHANGED