rochefort 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rochefort.rb +38 -15
- 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: fa87001a98b3f2cf7a5c008dba36df9425cd473e
|
4
|
+
data.tar.gz: 0f945723f6133643e4bd4c2ed144c0639177ff1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 688eab3f7fbaa1480e4205ac669ad8ba8e8f0841d0154cb3cda3003a6587281977daa288659a03e97113e9286b291d308acc6d73d87594cad4fa0f0f26822e8e
|
7
|
+
data.tar.gz: 9c52c1ea55bacb0b048ef5e5d2b2f7f4edbfaddf3b292ca4d78db00b0c2d5c56fd968b1f30957a7bb66e22ee3401836e48615c4caa017086ac5a490f618b08b0
|
data/lib/rochefort.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rest-client'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
# client for https://github.com/jackdoe/rochefort - disk speed append + offset service (poor man's kafka),
|
5
|
+
# client for https://github.com/jackdoe/rochefort - disk speed append + offset service (poor man's kafka),
|
6
6
|
# example usage
|
7
7
|
# r = new Rochefort("http://localhost:8001")
|
8
8
|
# offset = r.append(namespace: "example-namespace", data:"example-data")
|
@@ -14,6 +14,7 @@ class Rochefort
|
|
14
14
|
@urlModify = URI::join(url,'modify').to_s
|
15
15
|
@urlGet = URI::join(url,'get').to_s
|
16
16
|
@urlScan = URI::join(url,'scan').to_s
|
17
|
+
@urlQuery = URI::join(url,'query').to_s
|
17
18
|
@urlGetMulti = URI::join(url,'getMulti').to_s
|
18
19
|
end
|
19
20
|
|
@@ -60,7 +61,7 @@ class Rochefort
|
|
60
61
|
return out["success"]
|
61
62
|
end
|
62
63
|
|
63
|
-
|
64
|
+
|
64
65
|
# get data from rochefort
|
65
66
|
# r = Rochefort.new(url)
|
66
67
|
# r.get(
|
@@ -103,14 +104,8 @@ class Rochefort
|
|
103
104
|
return out
|
104
105
|
end
|
105
106
|
|
106
|
-
|
107
|
-
|
108
|
-
# r = Rochefort.new(url)
|
109
|
-
# r.scan(namespace: ns) do |len, offset, value|
|
110
|
-
# puts value
|
111
|
-
# end
|
112
|
-
# @return calls the block for each item
|
113
|
-
def scan(opts,&input_block)
|
107
|
+
|
108
|
+
def scanParser(input_block)
|
114
109
|
block = proc do |response|
|
115
110
|
buffer = ""
|
116
111
|
header_len = 12
|
@@ -124,7 +119,6 @@ class Rochefort
|
|
124
119
|
response.read_body do |chunk|
|
125
120
|
buffer << chunk
|
126
121
|
while buffer.length >= need
|
127
|
-
|
128
122
|
if waiting_for_header
|
129
123
|
h = buffer.unpack('l<q<')
|
130
124
|
len = h[0]
|
@@ -135,7 +129,7 @@ class Rochefort
|
|
135
129
|
end
|
136
130
|
|
137
131
|
if buffer.length >= need
|
138
|
-
input_block.call(
|
132
|
+
input_block.call(rochefort_offset, buffer[0, len])
|
139
133
|
buffer = buffer[len, buffer.length - len]
|
140
134
|
need = header_len
|
141
135
|
waiting_for_header = true
|
@@ -143,12 +137,41 @@ class Rochefort
|
|
143
137
|
end
|
144
138
|
end
|
145
139
|
end
|
140
|
+
return block
|
141
|
+
end
|
146
142
|
|
147
|
-
|
143
|
+
|
144
|
+
# scans a namespace, reading from a stream, so the namespace can be very big
|
145
|
+
# r = Rochefort.new(url)
|
146
|
+
# r.scan(namespace: ns) do |offset, value|
|
147
|
+
# puts value
|
148
|
+
# end
|
149
|
+
# @return calls the block for each item
|
150
|
+
def scan(opts,&input_block)
|
148
151
|
RestClient::Request.execute(method: :get,
|
149
|
-
url: "#{@urlScan}?namespace=#{opts[:namespace]}
|
152
|
+
url: "#{@urlScan}?namespace=#{opts[:namespace]}",
|
153
|
+
read_timeout: opts[:read_timeout] || 1,
|
154
|
+
open_timeout: opts[:open_timeout] || 1,
|
155
|
+
block_response: scanParser(input_block))
|
156
|
+
end
|
157
|
+
|
158
|
+
# searches a namespace, for the tagged /append blobs, reading from a stream, so the namespace can be very big
|
159
|
+
# r = Rochefort.new(url)
|
160
|
+
# r.search(query: {tag: 'a'}, namespace: ns) do |offset, value|
|
161
|
+
# puts value
|
162
|
+
# end
|
163
|
+
#
|
164
|
+
# the dsl is fairly simple: (A OR B OR (C AND D)
|
165
|
+
# {
|
166
|
+
# or: [ { tag: 'a' }, { tag: 'a' }, { and: [ {tag: 'c'}, {tag:'d'} ] } ]
|
167
|
+
# }
|
168
|
+
# @return calls the block for each item
|
169
|
+
def search(opts,&input_block)
|
170
|
+
RestClient::Request.execute(method: :post,
|
171
|
+
payload: JSON.generate(opts[:query]),
|
172
|
+
url: "#{@urlQuery}?namespace=#{opts[:namespace]}",
|
150
173
|
read_timeout: opts[:read_timeout] || 1,
|
151
174
|
open_timeout: opts[:open_timeout] || 1,
|
152
|
-
block_response:
|
175
|
+
block_response: scanParser(input_block))
|
153
176
|
end
|
154
177
|
end
|