disque 0.0.3 → 0.0.4

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: a9796d605e959e6f35a0496c2f9d809919d08121
4
- data.tar.gz: ac9b84f30b28dc50f030c9bb643fc192d9e3bcea
3
+ metadata.gz: 4ab3407c0c795f337c046fa94c96e67f9f2be51b
4
+ data.tar.gz: 8c0c0aedf7f7a97edf30512bc8558b8bca019bbe
5
5
  SHA512:
6
- metadata.gz: 52e663f3f5eb7bade1c2e28cb61d0e55a2b8974bdcb053c3ee991f2b57028e3b19436ff43e25093663e835d6a90946c16c78db266e7b19842ab5bb9ff62f3305
7
- data.tar.gz: ce21a8e38a1e953adc053eda602d9085dcdce54744fc9c4b74dd9b47e7eac2d189658fcb9ed6ee04954e59aef27c0fb2225fa2461095a3c54c798f30423e44a5
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.4.1
2
+ redic -v 1.5.0
@@ -0,0 +1,3 @@
1
+ 0.0.4
2
+
3
+ - Add AUTH option.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "disque"
5
- s.version = "0.0.3"
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
@@ -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
- sprintf("disque://%s", host)
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 by means of `CLUSTER NODES` and
56
- # keep a connection to the node that provided that information.
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("CLUSTER", "NODES").lines do |line|
67
- id, host, flag = line.split
68
-
69
- prefix = id[0,8]
73
+ result = @scout.call!("HELLO")
70
74
 
71
- if flag == "myself"
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
- # Configure main client
74
- @client.configure(@scout.url)
81
+ # Connect the main client to the first node that replied
82
+ @client.configure(@scout.url)
75
83
 
76
- # Keep track of selected node
77
- @prefix = prefix
78
- end
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
@@ -23,6 +23,7 @@ stop:
23
23
  --daemonize yes \
24
24
  --bind 127.0.0.1 \
25
25
  --loglevel notice \
26
+ --requirepass test \
26
27
  --pidfile disque.$@.pid \
27
28
  --appendfilename disque.$@.aof \
28
29
  --cluster-config-file disque.$@.nodes \
@@ -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://127.0.0.1:7710>\n", Silencer.output
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://127.0.0.1:7710>\n", Silencer.output
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: 0)
110
+ c.push("foo", "bar", 1000, async: true, ttl: 1)
111
111
 
112
- sleep 0.1
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
- assert prefix == c1.prefix
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.3
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-04-27 00:00:00.000000000 Z
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: '0'
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: '0'
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.3
66
+ rubygems_version: 2.0.14
66
67
  signing_key:
67
68
  specification_version: 4
68
69
  summary: Client for Disque