qrpc 0.1.0 → 0.1.1

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.
data/TODO.md CHANGED
@@ -1 +1,3 @@
1
- * general queue interface for ability to use more queue servers.
1
+ * general queue interface for ability to use more queue servers (starling, redis, ...)
2
+ * copyright headers to all files
3
+ * add @since 0.1.0 to all methods which haven't later @since
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # General QRPC module.
5
+ #
6
+
7
+ module QRPC
8
+
9
+ ##
10
+ # Prefix for handled queues.
11
+ #
12
+
13
+ QUEUE_PREFIX = "qrpc"
14
+
15
+ ##
16
+ # Input queue postfix.
17
+ #
18
+
19
+ QUEUE_POSTFIX_INPUT = "input"
20
+
21
+ ##
22
+ # Output queue postfix.
23
+ #
24
+
25
+ QUEUE_POSTFIX_OUTPUT = "output"
26
+
27
+ end
data/lib/qrpc/locator.rb CHANGED
@@ -62,7 +62,7 @@ module QRPC
62
62
 
63
63
  ##
64
64
  # Parses the locator.
65
- # Excpects form <queue>@<host>:<port>. Port is optional.
65
+ # Excpects form +<queue>@<host>:<port>+. Port is optional.
66
66
  #
67
67
  # @param [String] string locator in string form
68
68
  # @return [QRPC::Locator] new instance
data/lib/qrpc/server.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ require "qrpc/general"
2
3
  require "qrpc/server/job"
3
4
  require "qrpc/server/dispatcher"
4
5
  require "qrpc/locator"
@@ -6,7 +7,6 @@ require "em-beanstalk"
6
7
  require "eventmachine"
7
8
  require "base64"
8
9
 
9
-
10
10
  ##
11
11
  # General QRPC module.
12
12
  #
@@ -18,24 +18,27 @@ module QRPC
18
18
  #
19
19
 
20
20
  class Server
21
-
21
+
22
22
  ##
23
23
  # Prefix for handled queues.
24
+ # @deprecated (since 0.2.0)
24
25
  #
25
26
 
26
- QRPC_PREFIX = "qrpc"
27
+ QRPC_PREFIX = QRPC::QUEUE_PREFIX
27
28
 
28
29
  ##
29
30
  # Input queue postfix.
31
+ # @deprecated (since 0.2.0)
30
32
  #
31
33
 
32
- QRPC_POSTFIX_INPUT = "input"
34
+ QRPC_POSTFIX_INPUT = QRPC::QUEUE_POSTFIX_INPUT
33
35
 
34
36
  ##
35
37
  # Output queue postfix.
38
+ # @deprecated (since 0.2.0)
36
39
  #
37
40
 
38
- QRPC_POSTFIX_OUTPUT = "output"
41
+ QRPC_POSTFIX_OUTPUT = QRPC::QUEUE_POSTFIX_OUTPUT
39
42
 
40
43
  ##
41
44
  # Holds API instance.
@@ -49,6 +52,12 @@ module QRPC
49
52
 
50
53
  @locator
51
54
 
55
+ ##
56
+ # Holds input queue name.
57
+ #
58
+
59
+ @input_name
60
+
52
61
  ##
53
62
  # Holds output queue name.
54
63
  #
@@ -121,15 +130,15 @@ module QRPC
121
130
  #
122
131
 
123
132
  def finalize!
124
- if @input_queue
133
+ if not @input_queue.nil?
125
134
  @input_queue.watch("default") do
126
- @input_queue.ignore(@input_name) do
135
+ @input_queue.ignore(self.input_name.to_s) do
127
136
  @input_queue.close
128
137
  end
129
138
  end
130
139
  end
131
140
 
132
- if @output_queue
141
+ if not @output_queue.nil?
133
142
  @output_queue.use("default") do
134
143
  @output_queue.close
135
144
  end
@@ -161,7 +170,6 @@ module QRPC
161
170
 
162
171
  def start_listening(locator, opts)
163
172
  @locator = locator
164
- @locator.queue = self.class::QRPC_PREFIX.dup << "-" << @locator.queue << "-" << self.class::QRPC_POSTFIX_INPUT
165
173
  @dispatcher = QRPC::Server::Dispatcher::new(opts[:max_jobs])
166
174
 
167
175
  # Cache cleaning dispatcher
@@ -177,9 +185,6 @@ module QRPC
177
185
  end
178
186
  end
179
187
 
180
- ##
181
- #
182
-
183
188
  ##
184
189
  # Returns input queue.
185
190
  # (Callable from EM only.)
@@ -190,7 +195,7 @@ module QRPC
190
195
  def input_queue(&block)
191
196
  if not @input_queue
192
197
  @input_queue = EM::Beanstalk::new(:host => @locator.host, :port => @locator.port)
193
- @input_queue.watch(@locator.queue) do
198
+ @input_queue.watch(self.input_name.to_s) do
194
199
  @input_queue.ignore("default") do
195
200
  block.call(@input_queue)
196
201
  end
@@ -208,7 +213,7 @@ module QRPC
208
213
  #
209
214
 
210
215
  def output_queue
211
- if not @output_queue
216
+ if @output_queue.nil?
212
217
  @output_queue = EM::Beanstalk::new(:host => @locator.host, :port => @locator.port)
213
218
  end
214
219
 
@@ -226,7 +231,7 @@ module QRPC
226
231
  client_index = client.to_sym
227
232
 
228
233
  if not @output_name_cache.include? client_index
229
- output_name = self.class::QRPC_PREFIX.dup << "-" << client.to_s << "-" << self.class::QRPC_POSTFIX_OUTPUT
234
+ output_name = QRPC::QUEUE_PREFIX.dup << "-" << client.to_s << "-" << QRPC::QUEUE_POSTFIX_OUTPUT
230
235
  output_name = output_name.to_sym
231
236
  @output_name_cache[client_index] = output_name
232
237
  else
@@ -236,6 +241,22 @@ module QRPC
236
241
  return output_name
237
242
  end
238
243
 
244
+ ##
245
+ # Returns input name.
246
+ #
247
+ # @return [Symbol] input name
248
+ # @since 0.2.0
249
+ #
250
+
251
+ def input_name
252
+ if @input_name.nil?
253
+ @input_name = (QRPC::QUEUE_PREFIX.dup << "-" << @locator.queue << "-" << QRPC::QUEUE_POSTFIX_INPUT).to_sym
254
+ end
255
+
256
+ return @input_name
257
+ end
258
+
259
+
239
260
 
240
261
  protected
241
262
 
data/qrpc.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{qrpc}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Martin Kozák"]
12
- s.date = %q{2011-01-18}
12
+ s.date = %q{2011-01-29}
13
13
  s.email = %q{martinkozak@martinkozak.net}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "TODO.md",
26
26
  "VERSION",
27
+ "lib/qrpc/general.rb",
27
28
  "lib/qrpc/locator.rb",
28
29
  "lib/qrpc/server.rb",
29
30
  "lib/qrpc/server/dispatcher.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Martin Koz\xC3\xA1k"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-18 00:00:00 +01:00
17
+ date: 2011-01-29 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -124,6 +124,7 @@ files:
124
124
  - Rakefile
125
125
  - TODO.md
126
126
  - VERSION
127
+ - lib/qrpc/general.rb
127
128
  - lib/qrpc/locator.rb
128
129
  - lib/qrpc/server.rb
129
130
  - lib/qrpc/server/dispatcher.rb
@@ -145,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
146
  requirements:
146
147
  - - ">="
147
148
  - !ruby/object:Gem::Version
148
- hash: -3341094115904611072
149
+ hash: 3054544507503324892
149
150
  segments:
150
151
  - 0
151
152
  version: "0"