qrpc 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +11 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +8 -8
- data/README.md +31 -9
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/qrpc/client.rb +277 -0
- data/lib/qrpc/client/exception.rb +72 -0
- data/lib/qrpc/client/job.rb +150 -0
- data/lib/qrpc/general.rb +10 -0
- data/lib/qrpc/locator.rb +9 -6
- data/lib/qrpc/protocol/exception-data.rb +227 -0
- data/lib/qrpc/protocol/qrpc-object.rb +103 -0
- data/lib/qrpc/protocol/request.rb +46 -0
- data/lib/qrpc/server.rb +7 -10
- data/lib/qrpc/server/job.rb +9 -14
- data/qrpc.gemspec +17 -11
- data/test-client.rb +24 -0
- metadata +16 -38
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "json-rpc-objects/request"
|
3
|
+
require "qrpc/general"
|
4
|
+
require "qrpc/protocol/qrpc-object"
|
5
|
+
|
6
|
+
##
|
7
|
+
# General QRPC module.
|
8
|
+
#
|
9
|
+
|
10
|
+
module QRPC
|
11
|
+
|
12
|
+
##
|
13
|
+
# JSON RPC helper module.
|
14
|
+
# @since 0.2.0
|
15
|
+
#
|
16
|
+
|
17
|
+
module Protocol
|
18
|
+
|
19
|
+
##
|
20
|
+
# QRPC JSON-RPC request. Extends +JsonRpcObjects::Request+.
|
21
|
+
# See its documentation for additional reference.
|
22
|
+
#
|
23
|
+
# @since 0.2.0
|
24
|
+
#
|
25
|
+
|
26
|
+
class Request < JsonRpcObjects::Request
|
27
|
+
|
28
|
+
##
|
29
|
+
# Creates new QRPC request.
|
30
|
+
#
|
31
|
+
# @param [Symbol] client_id client (session) ID
|
32
|
+
# @param [Symbol] method job method name
|
33
|
+
# @param [Array] arguments array of arguments for job
|
34
|
+
# @param [Integer] priority job priority
|
35
|
+
# @param [Proc] callback result callback
|
36
|
+
# @return [QRPC::Protocol::Request] new protocol request object
|
37
|
+
#
|
38
|
+
|
39
|
+
def self.create(client_id, id, method, arguments = [ ], priority = QRPC::DEFAULT_PRIORITY)
|
40
|
+
qrpc = QRPC::Protocol::QrpcObject::create(:client => client_id, :priority => priority)
|
41
|
+
super(method, arguments, :id => id, :qrpc => qrpc)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/qrpc/server.rb
CHANGED
@@ -3,7 +3,8 @@ require "qrpc/general"
|
|
3
3
|
require "qrpc/server/job"
|
4
4
|
require "qrpc/server/dispatcher"
|
5
5
|
require "qrpc/locator"
|
6
|
-
require "
|
6
|
+
require "qrpc/protocol/qrpc-object"
|
7
|
+
require "em-jack"
|
7
8
|
require "eventmachine"
|
8
9
|
require "base64"
|
9
10
|
|
@@ -132,7 +133,7 @@ module QRPC
|
|
132
133
|
def finalize!
|
133
134
|
if not @input_queue.nil?
|
134
135
|
@input_queue.watch("default") do
|
135
|
-
@input_queue.ignore(
|
136
|
+
@input_queue.ignore(@input_name.to_s) do
|
136
137
|
@input_queue.close
|
137
138
|
end
|
138
139
|
end
|
@@ -187,14 +188,12 @@ module QRPC
|
|
187
188
|
|
188
189
|
##
|
189
190
|
# Returns input queue.
|
190
|
-
# (Callable from EM only.)
|
191
|
-
#
|
192
191
|
# @param [Proc] block block to which will be input queue given
|
193
192
|
#
|
194
193
|
|
195
194
|
def input_queue(&block)
|
196
195
|
if not @input_queue
|
197
|
-
@input_queue =
|
196
|
+
@input_queue = EMJack::Connection::new(:host => @locator.host, :port => @locator.port)
|
198
197
|
@input_queue.watch(self.input_name.to_s) do
|
199
198
|
@input_queue.ignore("default") do
|
200
199
|
block.call(@input_queue)
|
@@ -207,14 +206,12 @@ module QRPC
|
|
207
206
|
|
208
207
|
##
|
209
208
|
# Returns output queue.
|
210
|
-
#
|
211
|
-
#
|
212
|
-
# @return [EM::Beanstalk] output queue Beanstalk connection
|
209
|
+
# @return [EMJack::Connection] output queue Beanstalk connection
|
213
210
|
#
|
214
211
|
|
215
212
|
def output_queue
|
216
213
|
if @output_queue.nil?
|
217
|
-
@output_queue =
|
214
|
+
@output_queue = EMJack::Connection::new(:host => @locator.host, :port => @locator.port)
|
218
215
|
end
|
219
216
|
|
220
217
|
return @output_queue
|
@@ -245,7 +242,7 @@ module QRPC
|
|
245
242
|
# Returns input name.
|
246
243
|
#
|
247
244
|
# @return [Symbol] input name
|
248
|
-
# @since 0.
|
245
|
+
# @since 0.1.1
|
249
246
|
#
|
250
247
|
|
251
248
|
def input_name
|
data/lib/qrpc/server/job.rb
CHANGED
@@ -3,6 +3,9 @@ require "eventmachine"
|
|
3
3
|
require "json-rpc-objects/request"
|
4
4
|
require "json-rpc-objects/response"
|
5
5
|
require "json-rpc-objects/error"
|
6
|
+
require "qrpc/general"
|
7
|
+
require "qrpc/protocol/qrpc-object"
|
8
|
+
require "qrpc/protocol/exception-data"
|
6
9
|
|
7
10
|
|
8
11
|
##
|
@@ -21,9 +24,10 @@ module QRPC
|
|
21
24
|
|
22
25
|
##
|
23
26
|
# Indicates default priority.
|
27
|
+
# @deprecated (since 0.2.0)
|
24
28
|
#
|
25
29
|
|
26
|
-
DEFAULT_PRIORITY =
|
30
|
+
DEFAULT_PRIORITY = QRPC::DEFAULT_PRIORITY
|
27
31
|
|
28
32
|
##
|
29
33
|
# Holds beanstalk job.
|
@@ -71,12 +75,12 @@ module QRPC
|
|
71
75
|
end
|
72
76
|
|
73
77
|
response = request.class::version.response::create(result, error, :id => request.id)
|
74
|
-
response.qrpc =
|
78
|
+
response.qrpc = QRPC::Protocol::QrpcObject::create
|
75
79
|
|
76
80
|
@job.delete()
|
77
81
|
self.set_deferred_status(:succeeded, response.to_json)
|
78
82
|
end
|
79
|
-
|
83
|
+
|
80
84
|
##
|
81
85
|
# Returns job in request form.
|
82
86
|
# @return [JsonRpcObjects::Generic::Object] request associated to job
|
@@ -102,7 +106,7 @@ module QRPC
|
|
102
106
|
def priority
|
103
107
|
priority = self.request.qrpc["priority"]
|
104
108
|
if priority.nil?
|
105
|
-
priority =
|
109
|
+
priority = QRPC::DEFAULT_PRIORITY
|
106
110
|
else
|
107
111
|
priority = priority.to_i
|
108
112
|
end
|
@@ -127,16 +131,7 @@ module QRPC
|
|
127
131
|
#
|
128
132
|
|
129
133
|
def generate_error(request, exception)
|
130
|
-
data =
|
131
|
-
:name => exception.class.name,
|
132
|
-
:message => exception.message,
|
133
|
-
:backtrace => exception.backtrace.map { |s| Base64.encode64(s) },
|
134
|
-
:dump => {
|
135
|
-
:raw => Base64.encode64(Marshal.dump(exception)),
|
136
|
-
:format => :Ruby,
|
137
|
-
}
|
138
|
-
}
|
139
|
-
|
134
|
+
data = QRPC::Protocol::ExceptionData::create(exception)
|
140
135
|
request.class::version.error::create(100, "exception raised during processing the request", :error => data)
|
141
136
|
end
|
142
137
|
|
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.
|
8
|
+
s.version = "0.2.0"
|
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-
|
12
|
+
s.date = %q{2011-02-04}
|
13
13
|
s.email = %q{martinkozak@martinkozak.net}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
".document",
|
20
|
+
"CHANGES.txt",
|
20
21
|
"Gemfile",
|
21
22
|
"Gemfile.lock",
|
22
23
|
"LICENSE.txt",
|
@@ -24,8 +25,14 @@ Gem::Specification.new do |s|
|
|
24
25
|
"Rakefile",
|
25
26
|
"TODO.md",
|
26
27
|
"VERSION",
|
28
|
+
"lib/qrpc/client.rb",
|
29
|
+
"lib/qrpc/client/exception.rb",
|
30
|
+
"lib/qrpc/client/job.rb",
|
27
31
|
"lib/qrpc/general.rb",
|
28
32
|
"lib/qrpc/locator.rb",
|
33
|
+
"lib/qrpc/protocol/exception-data.rb",
|
34
|
+
"lib/qrpc/protocol/qrpc-object.rb",
|
35
|
+
"lib/qrpc/protocol/request.rb",
|
29
36
|
"lib/qrpc/server.rb",
|
30
37
|
"lib/qrpc/server/dispatcher.rb",
|
31
38
|
"lib/qrpc/server/job.rb",
|
@@ -36,32 +43,31 @@ Gem::Specification.new do |s|
|
|
36
43
|
s.homepage = %q{http://github.com/martinkozak/qrpc}
|
37
44
|
s.licenses = ["MIT"]
|
38
45
|
s.require_paths = ["lib"]
|
39
|
-
s.rubygems_version = %q{1.
|
40
|
-
s.summary = %q{Queued JSON-RPC server. Works as normal RPC server, but through queue interface, so allows highly scalable, distributed and asynchronous remote API implementation and fast data processing. It's based on eventmachine and beanstalkd, so it's fast and thread safe.}
|
46
|
+
s.rubygems_version = %q{1.5.0}
|
47
|
+
s.summary = %q{Queued JSON-RPC client and server. Works as normal RPC server, but through queue interface, so allows highly scalable, distributed and asynchronous remote API implementation and fast data processing. It's based on eventmachine and beanstalkd, so it's fast and thread safe.}
|
41
48
|
|
42
49
|
if s.respond_to? :specification_version then
|
43
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
50
|
s.specification_version = 3
|
45
51
|
|
46
52
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
-
s.add_runtime_dependency(%q<json-rpc-objects>, [">= 0.1
|
53
|
+
s.add_runtime_dependency(%q<json-rpc-objects>, [">= 0.3.1"])
|
48
54
|
s.add_runtime_dependency(%q<depq>, [">= 0.4"])
|
49
|
-
s.add_runtime_dependency(%q<em-
|
55
|
+
s.add_runtime_dependency(%q<em-jack>, [">= 0.1.3"])
|
50
56
|
s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.10"])
|
51
57
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
58
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
53
59
|
else
|
54
|
-
s.add_dependency(%q<json-rpc-objects>, [">= 0.1
|
60
|
+
s.add_dependency(%q<json-rpc-objects>, [">= 0.3.1"])
|
55
61
|
s.add_dependency(%q<depq>, [">= 0.4"])
|
56
|
-
s.add_dependency(%q<em-
|
62
|
+
s.add_dependency(%q<em-jack>, [">= 0.1.3"])
|
57
63
|
s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
|
58
64
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
65
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
60
66
|
end
|
61
67
|
else
|
62
|
-
s.add_dependency(%q<json-rpc-objects>, [">= 0.1
|
68
|
+
s.add_dependency(%q<json-rpc-objects>, [">= 0.3.1"])
|
63
69
|
s.add_dependency(%q<depq>, [">= 0.4"])
|
64
|
-
s.add_dependency(%q<em-
|
70
|
+
s.add_dependency(%q<em-jack>, [">= 0.1.3"])
|
65
71
|
s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
|
66
72
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
73
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
data/test-client.rb
CHANGED
@@ -1,4 +1,28 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.push("./lib")
|
4
|
+
require "qrpc/client"
|
5
|
+
require "qrpc/locator"
|
6
|
+
require "eventmachine"
|
7
|
+
|
8
|
+
EM::run do
|
9
|
+
client = QRPC::Client::new QRPC::Locator::new :test
|
10
|
+
puts client.inspect
|
11
|
+
|
12
|
+
client.subtract(2, 3) do |i|
|
13
|
+
puts i
|
14
|
+
end
|
15
|
+
|
16
|
+
client.subtract(3, 2) do |i|
|
17
|
+
puts i
|
18
|
+
end
|
19
|
+
|
20
|
+
client.something_bad do |i|
|
21
|
+
puts i
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
=begin
|
2
26
|
require "beanstalk-client"
|
3
27
|
require "json-rpc-objects/request"
|
4
28
|
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qrpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
version: 0.1.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- "Martin Koz\xC3\xA1k"
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-02-04 00:00:00 +01:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -24,11 +20,7 @@ dependencies:
|
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
- 0
|
29
|
-
- 1
|
30
|
-
- 2
|
31
|
-
version: 0.1.2
|
23
|
+
version: 0.3.1
|
32
24
|
type: :runtime
|
33
25
|
prerelease: false
|
34
26
|
version_requirements: *id001
|
@@ -39,25 +31,18 @@ dependencies:
|
|
39
31
|
requirements:
|
40
32
|
- - ">="
|
41
33
|
- !ruby/object:Gem::Version
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
- 4
|
45
34
|
version: "0.4"
|
46
35
|
type: :runtime
|
47
36
|
prerelease: false
|
48
37
|
version_requirements: *id002
|
49
38
|
- !ruby/object:Gem::Dependency
|
50
|
-
name: em-
|
39
|
+
name: em-jack
|
51
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
41
|
none: false
|
53
42
|
requirements:
|
54
43
|
- - ">="
|
55
44
|
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
- 0
|
58
|
-
- 0
|
59
|
-
- 10
|
60
|
-
version: 0.0.10
|
45
|
+
version: 0.1.3
|
61
46
|
type: :runtime
|
62
47
|
prerelease: false
|
63
48
|
version_requirements: *id003
|
@@ -68,10 +53,6 @@ dependencies:
|
|
68
53
|
requirements:
|
69
54
|
- - ">="
|
70
55
|
- !ruby/object:Gem::Version
|
71
|
-
segments:
|
72
|
-
- 0
|
73
|
-
- 12
|
74
|
-
- 10
|
75
56
|
version: 0.12.10
|
76
57
|
type: :runtime
|
77
58
|
prerelease: false
|
@@ -83,10 +64,6 @@ dependencies:
|
|
83
64
|
requirements:
|
84
65
|
- - ~>
|
85
66
|
- !ruby/object:Gem::Version
|
86
|
-
segments:
|
87
|
-
- 1
|
88
|
-
- 0
|
89
|
-
- 0
|
90
67
|
version: 1.0.0
|
91
68
|
type: :development
|
92
69
|
prerelease: false
|
@@ -98,10 +75,6 @@ dependencies:
|
|
98
75
|
requirements:
|
99
76
|
- - ~>
|
100
77
|
- !ruby/object:Gem::Version
|
101
|
-
segments:
|
102
|
-
- 1
|
103
|
-
- 5
|
104
|
-
- 2
|
105
78
|
version: 1.5.2
|
106
79
|
type: :development
|
107
80
|
prerelease: false
|
@@ -117,6 +90,7 @@ extra_rdoc_files:
|
|
117
90
|
- README.md
|
118
91
|
files:
|
119
92
|
- .document
|
93
|
+
- CHANGES.txt
|
120
94
|
- Gemfile
|
121
95
|
- Gemfile.lock
|
122
96
|
- LICENSE.txt
|
@@ -124,8 +98,14 @@ files:
|
|
124
98
|
- Rakefile
|
125
99
|
- TODO.md
|
126
100
|
- VERSION
|
101
|
+
- lib/qrpc/client.rb
|
102
|
+
- lib/qrpc/client/exception.rb
|
103
|
+
- lib/qrpc/client/job.rb
|
127
104
|
- lib/qrpc/general.rb
|
128
105
|
- lib/qrpc/locator.rb
|
106
|
+
- lib/qrpc/protocol/exception-data.rb
|
107
|
+
- lib/qrpc/protocol/qrpc-object.rb
|
108
|
+
- lib/qrpc/protocol/request.rb
|
129
109
|
- lib/qrpc/server.rb
|
130
110
|
- lib/qrpc/server/dispatcher.rb
|
131
111
|
- lib/qrpc/server/job.rb
|
@@ -146,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
126
|
requirements:
|
147
127
|
- - ">="
|
148
128
|
- !ruby/object:Gem::Version
|
149
|
-
hash:
|
129
|
+
hash: -3127609250093073389
|
150
130
|
segments:
|
151
131
|
- 0
|
152
132
|
version: "0"
|
@@ -155,15 +135,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
135
|
requirements:
|
156
136
|
- - ">="
|
157
137
|
- !ruby/object:Gem::Version
|
158
|
-
segments:
|
159
|
-
- 0
|
160
138
|
version: "0"
|
161
139
|
requirements: []
|
162
140
|
|
163
141
|
rubyforge_project:
|
164
|
-
rubygems_version: 1.
|
142
|
+
rubygems_version: 1.5.0
|
165
143
|
signing_key:
|
166
144
|
specification_version: 3
|
167
|
-
summary: Queued JSON-RPC server. Works as normal RPC server, but through queue interface, so allows highly scalable, distributed and asynchronous remote API implementation and fast data processing. It's based on eventmachine and beanstalkd, so it's fast and thread safe.
|
145
|
+
summary: Queued JSON-RPC client and server. Works as normal RPC server, but through queue interface, so allows highly scalable, distributed and asynchronous remote API implementation and fast data processing. It's based on eventmachine and beanstalkd, so it's fast and thread safe.
|
168
146
|
test_files: []
|
169
147
|
|