disque 0.0.3 → 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/.gems +1 -1
- data/CHANGELOG +3 -0
- data/disque.gemspec +2 -2
- data/lib/disque.rb +25 -17
- data/makefile +1 -0
- data/tests/disque_test.rb +21 -21
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ab3407c0c795f337c046fa94c96e67f9f2be51b
|
4
|
+
data.tar.gz: 8c0c0aedf7f7a97edf30512bc8558b8bca019bbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb908195fd598056f7af0f0e45834996b4ae57f479afada1b1b4e21177cc49e4083cfd2bf708736c451102656c33069ebaad29c8af3879d6b79f8b50d597338e
|
7
|
+
data.tar.gz: 63945a37c822eef761d2fa7f8dd5c75de68f91c54d319572a38d066481b2421feed6a4eb0de55553ba35b45e8e9e838a980ef2602a1699315f203fa89e6f3955
|
data/.gems
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
cutest -v 1.2.0
|
2
|
-
redic -v 1.
|
2
|
+
redic -v 1.5.0
|
data/CHANGELOG
ADDED
data/disque.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "disque"
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.4"
|
6
6
|
s.summary = "Client for Disque"
|
7
7
|
s.description = "Disque client for Ruby"
|
8
8
|
s.authors = ["Michel Martens", "Damian Janowski"]
|
@@ -11,5 +11,5 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.files = `git ls-files`.split("\n")
|
12
12
|
s.license = "MIT"
|
13
13
|
|
14
|
-
s.add_dependency "redic"
|
14
|
+
s.add_dependency "redic", "~> 1.5.0"
|
15
15
|
end
|
data/lib/disque.rb
CHANGED
@@ -22,7 +22,10 @@ class Disque
|
|
22
22
|
#
|
23
23
|
# TODO Account for authentication
|
24
24
|
# TODO Account for timeout
|
25
|
-
def initialize(hosts, cycle: 1000)
|
25
|
+
def initialize(hosts, auth: nil, cycle: 1000)
|
26
|
+
|
27
|
+
# Cluster password
|
28
|
+
@auth = auth
|
26
29
|
|
27
30
|
# Cycle length
|
28
31
|
@cycle = cycle
|
@@ -49,11 +52,15 @@ class Disque
|
|
49
52
|
end
|
50
53
|
|
51
54
|
def url(host)
|
52
|
-
|
55
|
+
if @auth
|
56
|
+
sprintf("disque://:%s@%s", @auth, host)
|
57
|
+
else
|
58
|
+
sprintf("disque://%s", host)
|
59
|
+
end
|
53
60
|
end
|
54
61
|
|
55
|
-
# Collect the list of nodes
|
56
|
-
#
|
62
|
+
# Collect the list of nodes and keep a connection to the
|
63
|
+
# node that provided that information.
|
57
64
|
def explore!(hosts)
|
58
65
|
|
59
66
|
# Reset nodes
|
@@ -63,21 +70,20 @@ class Disque
|
|
63
70
|
begin
|
64
71
|
@scout.configure(url(host))
|
65
72
|
|
66
|
-
@scout.call("
|
67
|
-
id, host, flag = line.split
|
68
|
-
|
69
|
-
prefix = id[0,8]
|
73
|
+
result = @scout.call!("HELLO")
|
70
74
|
|
71
|
-
|
75
|
+
# For keeping track of nodes and stats, we use only the
|
76
|
+
# first eight characters of the node_id. That's because
|
77
|
+
# those eight characters are part of the job_ids, and
|
78
|
+
# our stats are based on that.
|
79
|
+
@prefix = result[1][0,8]
|
72
80
|
|
73
|
-
|
74
|
-
|
81
|
+
# Connect the main client to the first node that replied
|
82
|
+
@client.configure(@scout.url)
|
75
83
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
@nodes[prefix] = host
|
84
|
+
# Populate cache with the list of node and their hosts
|
85
|
+
result[2..-1].each do |node_id, hostname, port, priority|
|
86
|
+
@nodes[node_id[0,8]] = sprintf("%s:%s", hostname, port)
|
81
87
|
end
|
82
88
|
|
83
89
|
@scout.quit
|
@@ -106,6 +112,8 @@ class Disque
|
|
106
112
|
|
107
113
|
# Reconfigure main client
|
108
114
|
@client.configure(url(host))
|
115
|
+
|
116
|
+
# Save current node prefix
|
109
117
|
@prefix = prefix
|
110
118
|
|
111
119
|
# Reset stats for this new connection
|
@@ -119,7 +127,7 @@ class Disque
|
|
119
127
|
# connection is lost, new connections are tried
|
120
128
|
# until all nodes become unavailable.
|
121
129
|
def call(*args)
|
122
|
-
@client.call(*args)
|
130
|
+
@client.call!(*args)
|
123
131
|
rescue *ECONN
|
124
132
|
explore!(@nodes.values)
|
125
133
|
retry
|
data/makefile
CHANGED
data/tests/disque_test.rb
CHANGED
@@ -33,24 +33,24 @@ DISQUE_GOOD_NODES = DISQUE_NODES[1,3]
|
|
33
33
|
test "raise if connection is not possible" do
|
34
34
|
Silencer.start
|
35
35
|
assert_raise(ArgumentError) do
|
36
|
-
c = Disque.new(DISQUE_BAD_NODES)
|
36
|
+
c = Disque.new(DISQUE_BAD_NODES, auth: "test")
|
37
37
|
end
|
38
38
|
Silencer.stop
|
39
39
|
|
40
|
-
assert_equal "#<Errno::ECONNREFUSED: Can't connect to: disque
|
40
|
+
assert_equal "#<Errno::ECONNREFUSED: Can't connect to: disque://:test@127.0.0.1:7710>\n", Silencer.output
|
41
41
|
end
|
42
42
|
|
43
43
|
test "retry until a connection is reached" do
|
44
44
|
Silencer.start
|
45
|
-
c = Disque.new(DISQUE_NODES)
|
45
|
+
c = Disque.new(DISQUE_NODES, auth: "test")
|
46
46
|
Silencer.stop
|
47
47
|
|
48
|
-
assert_equal "#<Errno::ECONNREFUSED: Can't connect to: disque
|
48
|
+
assert_equal "#<Errno::ECONNREFUSED: Can't connect to: disque://:test@127.0.0.1:7710>\n", Silencer.output
|
49
49
|
assert_equal "PONG", c.call("PING")
|
50
50
|
end
|
51
51
|
|
52
52
|
test "lack of jobs" do
|
53
|
-
c = Disque.new(DISQUE_GOOD_NODES)
|
53
|
+
c = Disque.new(DISQUE_GOOD_NODES, auth: "test")
|
54
54
|
reached = false
|
55
55
|
|
56
56
|
c.fetch(from: ["foo"], timeout: 1) do |job|
|
@@ -61,7 +61,7 @@ test "lack of jobs" do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
test "one job" do
|
64
|
-
c = Disque.new(DISQUE_GOOD_NODES)
|
64
|
+
c = Disque.new(DISQUE_GOOD_NODES, auth: "test")
|
65
65
|
|
66
66
|
c.push("foo", "bar", 1000)
|
67
67
|
|
@@ -71,7 +71,7 @@ test "one job" do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
test "multiple jobs" do
|
74
|
-
c = Disque.new(DISQUE_GOOD_NODES)
|
74
|
+
c = Disque.new(DISQUE_GOOD_NODES, auth: "test")
|
75
75
|
|
76
76
|
c.push("foo", "bar", 1000)
|
77
77
|
c.push("foo", "baz", 1000)
|
@@ -87,7 +87,7 @@ test "multiple jobs" do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
test "multiple queues" do
|
90
|
-
c = Disque.new(DISQUE_GOOD_NODES)
|
90
|
+
c = Disque.new(DISQUE_GOOD_NODES, auth: "test")
|
91
91
|
|
92
92
|
c.push("foo", "bar", 1000)
|
93
93
|
c.push("qux", "baz", 1000)
|
@@ -105,11 +105,11 @@ test "multiple queues" do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
test "add jobs with other parameters" do
|
108
|
-
c = Disque.new(DISQUE_GOOD_NODES)
|
108
|
+
c = Disque.new(DISQUE_GOOD_NODES, auth: "test")
|
109
109
|
|
110
|
-
c.push("foo", "bar", 1000, async: true, ttl:
|
110
|
+
c.push("foo", "bar", 1000, async: true, ttl: 1)
|
111
111
|
|
112
|
-
sleep
|
112
|
+
sleep 2
|
113
113
|
|
114
114
|
queues = ["foo"]
|
115
115
|
jobs = ["bar"]
|
@@ -124,8 +124,8 @@ test "add jobs with other parameters" do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
test "connect to the best node" do
|
127
|
-
c1 = Disque.new([DISQUE_GOOD_NODES[0]], cycle: 2)
|
128
|
-
c2 = Disque.new([DISQUE_GOOD_NODES[1]], cycle: 2)
|
127
|
+
c1 = Disque.new([DISQUE_GOOD_NODES[0]], cycle: 2, auth: "test")
|
128
|
+
c2 = Disque.new([DISQUE_GOOD_NODES[1]], cycle: 2, auth: "test")
|
129
129
|
|
130
130
|
assert c1.prefix != c2.prefix
|
131
131
|
|
@@ -146,8 +146,8 @@ test "connect to the best node" do
|
|
146
146
|
end
|
147
147
|
|
148
148
|
test "connect to the best node, part 2" do
|
149
|
-
c1 = Disque.new([DISQUE_GOOD_NODES[0]], cycle: 2)
|
150
|
-
c2 = Disque.new([DISQUE_GOOD_NODES[1]], cycle: 2)
|
149
|
+
c1 = Disque.new([DISQUE_GOOD_NODES[0]], cycle: 2, auth: "test")
|
150
|
+
c2 = Disque.new([DISQUE_GOOD_NODES[1]], cycle: 2, auth: "test")
|
151
151
|
|
152
152
|
assert c1.prefix != c2.prefix
|
153
153
|
|
@@ -164,7 +164,7 @@ test "connect to the best node, part 2" do
|
|
164
164
|
end
|
165
165
|
|
166
166
|
test "recover after node disconnection" do
|
167
|
-
c1 = Disque.new([DISQUE_GOOD_NODES[0]], cycle: 2)
|
167
|
+
c1 = Disque.new([DISQUE_GOOD_NODES[0]], cycle: 2, auth: "test")
|
168
168
|
|
169
169
|
prefix = c1.prefix
|
170
170
|
|
@@ -187,12 +187,12 @@ test "recover after node disconnection" do
|
|
187
187
|
c1.fetch(from: ["q1"])
|
188
188
|
|
189
189
|
# Prefix should stay the same
|
190
|
-
|
190
|
+
assert_equal prefix, c1.prefix
|
191
191
|
end
|
192
192
|
|
193
193
|
test "federation" do
|
194
|
-
c1 = Disque.new([DISQUE_GOOD_NODES[0]], cycle: 2)
|
195
|
-
c2 = Disque.new([DISQUE_GOOD_NODES[1]], cycle: 2)
|
194
|
+
c1 = Disque.new([DISQUE_GOOD_NODES[0]], cycle: 2, auth: "test")
|
195
|
+
c2 = Disque.new([DISQUE_GOOD_NODES[1]], cycle: 2, auth: "test")
|
196
196
|
|
197
197
|
c1.push("q1", "j1", 0)
|
198
198
|
|
@@ -202,7 +202,7 @@ test "federation" do
|
|
202
202
|
end
|
203
203
|
|
204
204
|
test "ack jobs when block is given" do
|
205
|
-
c = Disque.new(DISQUE_GOOD_NODES)
|
205
|
+
c = Disque.new(DISQUE_GOOD_NODES, auth: "test")
|
206
206
|
|
207
207
|
c.push("q1", "j1", 1000)
|
208
208
|
|
@@ -223,7 +223,7 @@ test "ack jobs when block is given" do
|
|
223
223
|
end
|
224
224
|
|
225
225
|
test "don't ack jobs when no block is given" do
|
226
|
-
c = Disque.new(DISQUE_GOOD_NODES)
|
226
|
+
c = Disque.new(DISQUE_GOOD_NODES, auth: "test")
|
227
227
|
|
228
228
|
c.push("q1", "j1", 1000)
|
229
229
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disque
|
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
|
- Michel Martens
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redic
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ~>
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 1.5.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 1.5.0
|
28
28
|
description: Disque client for Ruby
|
29
29
|
email:
|
30
30
|
- michel@soveran.com
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- .gems
|
37
37
|
- .gitignore
|
38
38
|
- AUTHORS
|
39
|
+
- CHANGELOG
|
39
40
|
- LICENSE
|
40
41
|
- README.md
|
41
42
|
- disque.gemspec
|
@@ -62,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
63
|
version: '0'
|
63
64
|
requirements: []
|
64
65
|
rubyforge_project:
|
65
|
-
rubygems_version: 2.0.
|
66
|
+
rubygems_version: 2.0.14
|
66
67
|
signing_key:
|
67
68
|
specification_version: 4
|
68
69
|
summary: Client for Disque
|