disque 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +55 -3
- data/disque.gemspec +1 -1
- data/lib/disque.rb +10 -1
- data/tests/disque_test.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 567ba45ec3c94e38a4cdd18cc6a58db6960cb6cf
|
4
|
+
data.tar.gz: f6e258e52e77636493ada87f131ce8495ef97c85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f933756f0b4165e327f8ce4ea93315d527806bfb9b6a20a5af0c3d2dad25eb219fb06c610410a561f88446ba1c12bbac292126369c9e924ec2c8fde614e0caa
|
7
|
+
data.tar.gz: 8f3ad9b91c3d16703fa1d77ae1d64be07108ed59bcf3225c1782d16a773413abcd5eb63c39a1ba4dae6973eab67140443b40952b71528323438b71070060fe8e
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -12,15 +12,60 @@ Create a new Disque client by passing a list of nodes:
|
|
12
12
|
client = Disque.new(["127.0.0.1:7711", "127.0.0.1:7712", "127.0.0.1:7713"])
|
13
13
|
```
|
14
14
|
|
15
|
+
Alternatively, you can pass a single string with comma-separated nodes:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
client = Disque.new("127.0.0.1:7711,127.0.0.1:7712,127.0.0.1:7713")
|
19
|
+
```
|
20
|
+
|
21
|
+
Using a single string is useful if you are receiving the list of nodes
|
22
|
+
from an environment variable.
|
23
|
+
|
24
|
+
If the nodes are password protected, you can pass the `AUTH` string:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
client = Disque.new("127.0.0.1:7711", auth: "e727d1464a...")
|
28
|
+
```
|
29
|
+
|
30
|
+
The client keeps track of which nodes are providing more jobs, and after
|
31
|
+
a given number operations it tries to connect to the preferred node. The
|
32
|
+
number of operations for each cycle defaults to 1000, but it can be
|
33
|
+
configured:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
client = Disque.new("127.0.0.1:7711", cycle: 20000)
|
37
|
+
```
|
38
|
+
|
15
39
|
Now you can add jobs:
|
16
40
|
|
17
41
|
```ruby
|
18
42
|
client.push("foo", "bar", 100)
|
19
43
|
```
|
20
44
|
|
21
|
-
It will push the job "bar" to the queue "foo" with a timeout
|
22
|
-
ms, and return the id of the job if it was received and
|
23
|
-
in time.
|
45
|
+
It will push the job `"bar"` to the queue `"foo"` with a timeout
|
46
|
+
of 100 ms, and return the id of the job if it was received and
|
47
|
+
replicated in time.
|
48
|
+
|
49
|
+
Disque's `ADDJOB` signature is as follows:
|
50
|
+
|
51
|
+
```
|
52
|
+
ADDJOB queue_name job <ms-timeout>
|
53
|
+
[REPLICATE <count>]
|
54
|
+
[DELAY <sec>]
|
55
|
+
[RETRY <sec>]
|
56
|
+
[TTL <sec>]
|
57
|
+
[MAXLEN <count>]
|
58
|
+
[ASYNC]
|
59
|
+
```
|
60
|
+
|
61
|
+
You can pass any optional arguments as a hash, for example:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
disque.push("foo", "myjob", 1000, ttl: 1, async: true)
|
65
|
+
```
|
66
|
+
|
67
|
+
Note that `async` is a special case because it's just a flag. That's
|
68
|
+
why `true` must be passed as its value.
|
24
69
|
|
25
70
|
Then, your workers will do something like this:
|
26
71
|
|
@@ -32,6 +77,13 @@ loop do
|
|
32
77
|
end
|
33
78
|
```
|
34
79
|
|
80
|
+
The `fetch` command receives an array of queues, and optionally a
|
81
|
+
`timeout` (in milliseconds) and the `count` of jobs to retrieve:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
client.fetch(from: ["bar", "baz"], count: 10, timeout: 2000)
|
85
|
+
```
|
86
|
+
|
35
87
|
Installation
|
36
88
|
------------
|
37
89
|
|
data/disque.gemspec
CHANGED
data/lib/disque.rb
CHANGED
@@ -14,16 +14,25 @@ class Disque
|
|
14
14
|
#
|
15
15
|
# Disque.new(["127.0.0.1:7711", "127.0.0.1:7712", "127.0.0.1:7713"])
|
16
16
|
#
|
17
|
+
# Alternatively, you can pass a single string with a comma-separated
|
18
|
+
# list of nodes:
|
19
|
+
#
|
20
|
+
# Disque.new("127.0.0.1:7711,127.0.0.1:7712,127.0.0.1:7713")
|
21
|
+
#
|
17
22
|
# For each operation, a counter is updated to signal which node was
|
18
23
|
# the originator of the message. Based on that information, after
|
19
24
|
# a full cycle (1000 operations, but configurable on initialization)
|
20
25
|
# the stats are checked to see what is the most convenient node
|
21
26
|
# to connect to in order to avoid extra jumps.
|
22
27
|
#
|
23
|
-
# TODO Account for authentication
|
24
28
|
# TODO Account for timeout
|
25
29
|
def initialize(hosts, auth: nil, cycle: 1000)
|
26
30
|
|
31
|
+
# Split a string of hosts if necessary
|
32
|
+
if String === hosts
|
33
|
+
hosts = hosts.split(",")
|
34
|
+
end
|
35
|
+
|
27
36
|
# Cluster password
|
28
37
|
@auth = auth
|
29
38
|
|
data/tests/disque_test.rb
CHANGED
@@ -235,3 +235,12 @@ test "don't ack jobs when no block is given" do
|
|
235
235
|
|
236
236
|
assert_equal info.fetch("state"), "active"
|
237
237
|
end
|
238
|
+
|
239
|
+
test "receive a string of comma-separated nodes" do
|
240
|
+
nodes = DISQUE_GOOD_NODES.join(",")
|
241
|
+
|
242
|
+
c = Disque.new(nodes, auth: "test")
|
243
|
+
|
244
|
+
assert_equal "PONG", c.call("PING")
|
245
|
+
assert_equal DISQUE_GOOD_NODES.size, c.nodes.size
|
246
|
+
end
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redic
|