cloudist 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/VERSION +1 -1
- data/cloudist.gemspec +13 -5
- data/examples/extending_values.rb +44 -0
- data/examples/sandwich_client.rb +18 -4
- data/examples/sandwich_worker.rb +12 -18
- data/examples/sandwich_worker_with_class.rb +37 -0
- data/lib/cloudist.rb +101 -17
- data/lib/cloudist/callbacks/error_callback.rb +14 -0
- data/lib/cloudist/core_ext/object.rb +81 -0
- data/lib/cloudist/errors.rb +1 -1
- data/lib/cloudist/job.rb +19 -4
- data/lib/cloudist/listener.rb +14 -2
- data/lib/cloudist/payload.rb +21 -11
- data/lib/cloudist/queues/basic_queue.rb +101 -0
- data/lib/cloudist/{job_queue.rb → queues/job_queue.rb} +2 -2
- data/lib/cloudist/{reply_queue.rb → queues/reply_queue.rb} +1 -1
- data/lib/cloudist/request.rb +2 -2
- data/lib/cloudist/utils.rb +16 -0
- data/lib/cloudist/worker.rb +20 -11
- data/spec/cloudist/basic_queue_spec.rb +2 -2
- data/spec/cloudist/payload_spec.rb +23 -18
- data/spec/cloudist/request_spec.rb +2 -2
- data/spec/cloudist/utils_spec.rb +19 -0
- data/spec/cloudist_spec.rb +42 -11
- metadata +61 -53
- data/lib/cloudist/basic_queue.rb +0 -92
@@ -3,11 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
|
3
3
|
describe Cloudist::Request do
|
4
4
|
before {
|
5
5
|
@mq_header = mock("MQ::Header")
|
6
|
-
@mq_header.stubs(:
|
6
|
+
@mq_header.stubs(:headers).returns({:published_on=>Time.now.to_i - 60, :event_hash=>"foo", :message_id=>"foo", :ttl=>300})
|
7
7
|
|
8
8
|
q = Cloudist::JobQueue.new('test.queue')
|
9
9
|
|
10
|
-
@request = Cloudist::Request.new(q, {:bread => 'white'}
|
10
|
+
@request = Cloudist::Request.new(q, Marshal.dump({:bread => 'white'}), @mq_header)
|
11
11
|
}
|
12
12
|
|
13
13
|
it "should return ttl" do
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
2
|
+
|
3
|
+
describe Cloudist::Utils do
|
4
|
+
it "should return reply queue name" do
|
5
|
+
Cloudist::Utils.reply_prefix('eat.sandwich').should == 'temp.reply.eat.sandwich'
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return log queue name" do
|
9
|
+
Cloudist::Utils.log_prefix('eat.sandwich').should == 'temp.log.eat.sandwich'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return stats queue name" do
|
13
|
+
Cloudist::Utils.stats_prefix('eat.sandwich').should == 'temp.stats.eat.sandwich'
|
14
|
+
end
|
15
|
+
|
16
|
+
# it "should generate queue name" do
|
17
|
+
# Cloudist::Utils.generate_queue('test').should == ''
|
18
|
+
# end
|
19
|
+
end
|
data/spec/cloudist_spec.rb
CHANGED
@@ -1,24 +1,55 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require "moqueue"
|
3
|
+
|
4
|
+
class SandwichWorker < Cloudist::Worker
|
5
|
+
def process
|
6
|
+
Cloudist.log.info(job.data.inspect)
|
7
|
+
end
|
8
|
+
end
|
2
9
|
|
3
10
|
describe "Cloudist" do
|
4
11
|
|
5
12
|
before(:each) do
|
6
13
|
overload_amqp
|
7
14
|
reset_broker
|
15
|
+
Cloudist.remove_workers
|
16
|
+
|
17
|
+
@mq = mock("MQ")
|
18
|
+
@queue, @exchange = mock_queue_and_exchange('make.sandwich')
|
19
|
+
|
20
|
+
@qobj = Cloudist::JobQueue.any_instance
|
21
|
+
@qobj.stubs(:q).returns(@queue)
|
22
|
+
@qobj.stubs(:mq).returns(@mq)
|
23
|
+
@qobj.stubs(:ex).returns(@exchange)
|
24
|
+
@qobj.stubs(:setup)
|
8
25
|
end
|
9
26
|
|
10
|
-
|
11
|
-
Cloudist.
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
}
|
27
|
+
it "should register a worker" do
|
28
|
+
Cloudist.register_worker('make.sandwich', SandwichWorker)
|
29
|
+
Cloudist.workers.should have_key("make.sandwich")
|
30
|
+
Cloudist.workers["make.sandwich"].size.should == 1
|
16
31
|
end
|
17
32
|
|
18
|
-
it "should
|
19
|
-
Cloudist.
|
20
|
-
Cloudist.
|
21
|
-
|
22
|
-
|
33
|
+
it "should support handle syntax" do
|
34
|
+
Cloudist.workers.should == {}
|
35
|
+
Cloudist.handle('make.sandwich').with(SandwichWorker)
|
36
|
+
Cloudist.workers.should have_key("make.sandwich")
|
37
|
+
Cloudist.workers["make.sandwich"].size.should == 1
|
23
38
|
end
|
39
|
+
|
40
|
+
# it "should support handle syntax with multiple queues" do
|
41
|
+
# Cloudist.workers.should == {}
|
42
|
+
# Cloudist.handle('make.sandwich', 'eat.sandwich').with(SandwichWorker)
|
43
|
+
# # Cloudist.workers.should == {"make.sandwich"=>[SandwichWorker], "eat.sandwich"=>[SandwichWorker]}
|
44
|
+
# end
|
45
|
+
|
46
|
+
it "should call process on worker when job arrives" do
|
47
|
+
job = Cloudist.enqueue('make.sandwich', {:bread => 'white'})
|
48
|
+
job.payload.published?.should be_true
|
49
|
+
SandwichWorker.any_instance.expects(:process)
|
50
|
+
Cloudist.handle('make.sandwich').with(SandwichWorker)
|
51
|
+
Cloudist.workers.should have_key("make.sandwich")
|
52
|
+
Cloudist.workers["make.sandwich"].size.should == 1
|
53
|
+
end
|
54
|
+
|
24
55
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ivan Vanderbyl
|
@@ -15,11 +15,14 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-20 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
name: amqp
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
26
|
none: false
|
24
27
|
requirements:
|
25
28
|
- - ~>
|
@@ -30,12 +33,12 @@ dependencies:
|
|
30
33
|
- 6
|
31
34
|
- 7
|
32
35
|
version: 0.6.7
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
33
38
|
type: :runtime
|
34
|
-
name: amqp
|
35
39
|
prerelease: false
|
36
|
-
|
37
|
-
|
38
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
name: json
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
42
|
none: false
|
40
43
|
requirements:
|
41
44
|
- - ~>
|
@@ -46,12 +49,12 @@ dependencies:
|
|
46
49
|
- 4
|
47
50
|
- 6
|
48
51
|
version: 1.4.6
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
49
54
|
type: :runtime
|
50
|
-
name: json
|
51
55
|
prerelease: false
|
52
|
-
|
53
|
-
|
54
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
name: activesupport
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
58
|
none: false
|
56
59
|
requirements:
|
57
60
|
- - ~>
|
@@ -62,12 +65,12 @@ dependencies:
|
|
62
65
|
- 0
|
63
66
|
- 3
|
64
67
|
version: 3.0.3
|
65
|
-
|
66
|
-
name: activesupport
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: *id003
|
68
|
+
requirement: *id003
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
name: rspec
|
73
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
74
|
none: false
|
72
75
|
requirements:
|
73
76
|
- - ~>
|
@@ -78,12 +81,12 @@ dependencies:
|
|
78
81
|
- 3
|
79
82
|
- 0
|
80
83
|
version: 2.3.0
|
84
|
+
requirement: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
81
86
|
type: :development
|
82
|
-
name: rspec
|
83
87
|
prerelease: false
|
84
|
-
|
85
|
-
|
86
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
88
|
+
name: moqueue
|
89
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
87
90
|
none: false
|
88
91
|
requirements:
|
89
92
|
- - ">="
|
@@ -92,12 +95,12 @@ dependencies:
|
|
92
95
|
segments:
|
93
96
|
- 0
|
94
97
|
version: "0"
|
98
|
+
requirement: *id005
|
99
|
+
- !ruby/object:Gem::Dependency
|
95
100
|
type: :development
|
96
|
-
name: moqueue
|
97
101
|
prerelease: false
|
98
|
-
|
99
|
-
|
100
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
102
|
+
name: mocha
|
103
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
101
104
|
none: false
|
102
105
|
requirements:
|
103
106
|
- - ">="
|
@@ -106,12 +109,12 @@ dependencies:
|
|
106
109
|
segments:
|
107
110
|
- 0
|
108
111
|
version: "0"
|
112
|
+
requirement: *id006
|
113
|
+
- !ruby/object:Gem::Dependency
|
109
114
|
type: :development
|
110
|
-
name: mocha
|
111
115
|
prerelease: false
|
112
|
-
|
113
|
-
|
114
|
-
requirement: &id007 !ruby/object:Gem::Requirement
|
116
|
+
name: bundler
|
117
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
115
118
|
none: false
|
116
119
|
requirements:
|
117
120
|
- - ~>
|
@@ -122,12 +125,12 @@ dependencies:
|
|
122
125
|
- 0
|
123
126
|
- 0
|
124
127
|
version: 1.0.0
|
128
|
+
requirement: *id007
|
129
|
+
- !ruby/object:Gem::Dependency
|
125
130
|
type: :development
|
126
|
-
name: bundler
|
127
131
|
prerelease: false
|
128
|
-
|
129
|
-
|
130
|
-
requirement: &id008 !ruby/object:Gem::Requirement
|
132
|
+
name: jeweler
|
133
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
131
134
|
none: false
|
132
135
|
requirements:
|
133
136
|
- - ~>
|
@@ -138,12 +141,12 @@ dependencies:
|
|
138
141
|
- 5
|
139
142
|
- 2
|
140
143
|
version: 1.5.2
|
144
|
+
requirement: *id008
|
145
|
+
- !ruby/object:Gem::Dependency
|
141
146
|
type: :development
|
142
|
-
name: jeweler
|
143
147
|
prerelease: false
|
144
|
-
|
145
|
-
|
146
|
-
requirement: &id009 !ruby/object:Gem::Requirement
|
148
|
+
name: rcov
|
149
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
147
150
|
none: false
|
148
151
|
requirements:
|
149
152
|
- - ">="
|
@@ -152,12 +155,12 @@ dependencies:
|
|
152
155
|
segments:
|
153
156
|
- 0
|
154
157
|
version: "0"
|
158
|
+
requirement: *id009
|
159
|
+
- !ruby/object:Gem::Dependency
|
155
160
|
type: :development
|
156
|
-
name: rcov
|
157
161
|
prerelease: false
|
158
|
-
|
159
|
-
|
160
|
-
requirement: &id010 !ruby/object:Gem::Requirement
|
162
|
+
name: reek
|
163
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
161
164
|
none: false
|
162
165
|
requirements:
|
163
166
|
- - ~>
|
@@ -168,12 +171,12 @@ dependencies:
|
|
168
171
|
- 2
|
169
172
|
- 8
|
170
173
|
version: 1.2.8
|
174
|
+
requirement: *id010
|
175
|
+
- !ruby/object:Gem::Dependency
|
171
176
|
type: :development
|
172
|
-
name: reek
|
173
177
|
prerelease: false
|
174
|
-
|
175
|
-
|
176
|
-
requirement: &id011 !ruby/object:Gem::Requirement
|
178
|
+
name: roodi
|
179
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
177
180
|
none: false
|
178
181
|
requirements:
|
179
182
|
- - ~>
|
@@ -184,10 +187,7 @@ dependencies:
|
|
184
187
|
- 1
|
185
188
|
- 0
|
186
189
|
version: 2.1.0
|
187
|
-
|
188
|
-
name: roodi
|
189
|
-
prerelease: false
|
190
|
-
version_requirements: *id011
|
190
|
+
requirement: *id011
|
191
191
|
description: Cloudist is a simple, highly scalable job queue for Ruby applications, it can run within Rails, DaemonKit or your own custom application. Refer to github page for examples
|
192
192
|
email: ivanvanderbyl@me.com
|
193
193
|
executables: []
|
@@ -207,21 +207,25 @@ files:
|
|
207
207
|
- Rakefile
|
208
208
|
- VERSION
|
209
209
|
- cloudist.gemspec
|
210
|
+
- examples/extending_values.rb
|
210
211
|
- examples/queue_message.rb
|
211
212
|
- examples/sandwich_client.rb
|
212
213
|
- examples/sandwich_worker.rb
|
214
|
+
- examples/sandwich_worker_with_class.rb
|
213
215
|
- lib/cloudist.rb
|
214
|
-
- lib/cloudist/basic_queue.rb
|
215
216
|
- lib/cloudist/callback.rb
|
216
217
|
- lib/cloudist/callback_methods.rb
|
218
|
+
- lib/cloudist/callbacks/error_callback.rb
|
219
|
+
- lib/cloudist/core_ext/object.rb
|
217
220
|
- lib/cloudist/core_ext/string.rb
|
218
221
|
- lib/cloudist/errors.rb
|
219
222
|
- lib/cloudist/job.rb
|
220
|
-
- lib/cloudist/job_queue.rb
|
221
223
|
- lib/cloudist/listener.rb
|
222
224
|
- lib/cloudist/payload.rb
|
223
225
|
- lib/cloudist/publisher.rb
|
224
|
-
- lib/cloudist/
|
226
|
+
- lib/cloudist/queues/basic_queue.rb
|
227
|
+
- lib/cloudist/queues/job_queue.rb
|
228
|
+
- lib/cloudist/queues/reply_queue.rb
|
225
229
|
- lib/cloudist/request.rb
|
226
230
|
- lib/cloudist/utils.rb
|
227
231
|
- lib/cloudist/worker.rb
|
@@ -229,6 +233,7 @@ files:
|
|
229
233
|
- spec/cloudist/job_spec.rb
|
230
234
|
- spec/cloudist/payload_spec.rb
|
231
235
|
- spec/cloudist/request_spec.rb
|
236
|
+
- spec/cloudist/utils_spec.rb
|
232
237
|
- spec/cloudist_spec.rb
|
233
238
|
- spec/core_ext/string_spec.rb
|
234
239
|
- spec/spec_helper.rb
|
@@ -267,13 +272,16 @@ signing_key:
|
|
267
272
|
specification_version: 3
|
268
273
|
summary: Super fast job queue using AMQP
|
269
274
|
test_files:
|
275
|
+
- examples/extending_values.rb
|
270
276
|
- examples/queue_message.rb
|
271
277
|
- examples/sandwich_client.rb
|
272
278
|
- examples/sandwich_worker.rb
|
279
|
+
- examples/sandwich_worker_with_class.rb
|
273
280
|
- spec/cloudist/basic_queue_spec.rb
|
274
281
|
- spec/cloudist/job_spec.rb
|
275
282
|
- spec/cloudist/payload_spec.rb
|
276
283
|
- spec/cloudist/request_spec.rb
|
284
|
+
- spec/cloudist/utils_spec.rb
|
277
285
|
- spec/cloudist_spec.rb
|
278
286
|
- spec/core_ext/string_spec.rb
|
279
287
|
- spec/spec_helper.rb
|
data/lib/cloudist/basic_queue.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
module Cloudist
|
2
|
-
class UnknownReplyTo < RuntimeError; end
|
3
|
-
class ExpiredMessage < RuntimeError; end
|
4
|
-
|
5
|
-
class BasicQueue
|
6
|
-
attr_reader :queue_name, :opts
|
7
|
-
attr_reader :q, :ex, :mq
|
8
|
-
|
9
|
-
def initialize(queue_name, opts = {})
|
10
|
-
opts = {
|
11
|
-
:auto_delete => true,
|
12
|
-
:durable => false,
|
13
|
-
:prefetch => 1
|
14
|
-
}.update(opts)
|
15
|
-
|
16
|
-
@queue_name, @opts = queue_name, opts
|
17
|
-
end
|
18
|
-
|
19
|
-
def setup
|
20
|
-
return if @setup == true
|
21
|
-
|
22
|
-
@mq = MQ.new
|
23
|
-
@q = @mq.queue(queue_name, opts)
|
24
|
-
# if we don't specify an exchange name it defaults to the queue_name
|
25
|
-
@ex = @mq.direct(opts[:exchange_name] || queue_name)
|
26
|
-
|
27
|
-
q.bind(ex) if ex
|
28
|
-
|
29
|
-
@setup = true
|
30
|
-
end
|
31
|
-
|
32
|
-
def log
|
33
|
-
Cloudist.log
|
34
|
-
end
|
35
|
-
|
36
|
-
def tag
|
37
|
-
s = "queue=#{q.name}"
|
38
|
-
s += " exchange=#{ex.name}" if ex
|
39
|
-
s
|
40
|
-
end
|
41
|
-
|
42
|
-
def subscribe(amqp_opts={}, opts={})
|
43
|
-
setup
|
44
|
-
|
45
|
-
q.subscribe(amqp_opts) do |queue_header, json_encoded_message|
|
46
|
-
return if Cloudist.closing?
|
47
|
-
|
48
|
-
request = Cloudist::Request.new(self, json_encoded_message, queue_header)
|
49
|
-
|
50
|
-
begin
|
51
|
-
raise Cloudist::ExpiredMessage if request.expired?
|
52
|
-
yield request if block_given?
|
53
|
-
finished = Time.now.utc.to_i
|
54
|
-
|
55
|
-
rescue Cloudist::ExpiredMessage
|
56
|
-
log.info "amqp_message action=timeout #{tag} ttl=#{request.ttl} age=#{request.age} #{request.inspect}"
|
57
|
-
request.ack if amqp_opts[:ack]
|
58
|
-
|
59
|
-
rescue => e
|
60
|
-
request.ack if amqp_opts[:ack]
|
61
|
-
Cloudist.handle_error(e)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
log.info "amqp_subscribe #{tag}"
|
65
|
-
self
|
66
|
-
end
|
67
|
-
|
68
|
-
def publish(payload)
|
69
|
-
payload.set_reply_to(queue_name)
|
70
|
-
body, headers = payload.formatted
|
71
|
-
ex.publish(body, headers)
|
72
|
-
payload.publish
|
73
|
-
end
|
74
|
-
|
75
|
-
def publish_to_q(payload)
|
76
|
-
body, headers = payload.formatted
|
77
|
-
q.publish(body, headers)
|
78
|
-
payload.publish
|
79
|
-
return headers
|
80
|
-
end
|
81
|
-
|
82
|
-
def teardown
|
83
|
-
@q.unsubscribe
|
84
|
-
@mq.close
|
85
|
-
log.debug "amqp_unsubscribe #{tag}"
|
86
|
-
end
|
87
|
-
|
88
|
-
def destroy
|
89
|
-
teardown
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|