cloudist 0.2.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +15 -11
- data/Gemfile.lock +20 -7
- data/README.md +61 -39
- data/VERSION +1 -1
- data/cloudist.gemspec +50 -16
- data/examples/amqp/Gemfile +3 -0
- data/examples/amqp/Gemfile.lock +12 -0
- data/examples/amqp/amqp_consumer.rb +56 -0
- data/examples/amqp/amqp_publisher.rb +50 -0
- data/examples/queue_message.rb +7 -7
- data/examples/sandwich_client_with_custom_listener.rb +77 -0
- data/examples/sandwich_worker_with_class.rb +22 -7
- data/lib/cloudist.rb +113 -56
- data/lib/cloudist/application.rb +60 -0
- data/lib/cloudist/core_ext/class.rb +139 -0
- data/lib/cloudist/core_ext/kernel.rb +13 -0
- data/lib/cloudist/core_ext/module.rb +11 -0
- data/lib/cloudist/encoding.rb +13 -0
- data/lib/cloudist/errors.rb +2 -0
- data/lib/cloudist/job.rb +21 -18
- data/lib/cloudist/listener.rb +108 -54
- data/lib/cloudist/message.rb +97 -0
- data/lib/cloudist/messaging.rb +29 -0
- data/lib/cloudist/payload.rb +45 -105
- data/lib/cloudist/payload_old.rb +155 -0
- data/lib/cloudist/publisher.rb +7 -2
- data/lib/cloudist/queue.rb +152 -0
- data/lib/cloudist/queues/basic_queue.rb +83 -53
- data/lib/cloudist/queues/job_queue.rb +13 -24
- data/lib/cloudist/queues/reply_queue.rb +13 -21
- data/lib/cloudist/request.rb +33 -7
- data/lib/cloudist/worker.rb +9 -2
- data/lib/cloudist_old.rb +300 -0
- data/lib/em/em_timer_utils.rb +55 -0
- data/lib/em/iterator.rb +27 -0
- data/spec/cloudist/message_spec.rb +91 -0
- data/spec/cloudist/messaging_spec.rb +19 -0
- data/spec/cloudist/payload_spec.rb +10 -4
- data/spec/cloudist/payload_spec_2_spec.rb +78 -0
- data/spec/cloudist/queue_spec.rb +16 -0
- data/spec/cloudist_spec.rb +49 -45
- data/spec/spec_helper.rb +0 -1
- data/spec/support/amqp.rb +16 -0
- metadata +112 -102
- data/examples/extending_values.rb +0 -44
- data/examples/sandwich_client.rb +0 -57
- data/lib/cloudist/callback.rb +0 -16
- data/lib/cloudist/callback_methods.rb +0 -19
- data/lib/cloudist/callbacks/error_callback.rb +0 -14
@@ -1,44 +0,0 @@
|
|
1
|
-
class SandwichMaker
|
2
|
-
|
3
|
-
end
|
4
|
-
|
5
|
-
class SandwichEater
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
module Cloudist
|
10
|
-
class << self
|
11
|
-
@@workers = {}
|
12
|
-
|
13
|
-
def handle(*queue_names)
|
14
|
-
class << queue_names
|
15
|
-
def with(handler)
|
16
|
-
self.each do |queue_name|
|
17
|
-
((@@workers[queue_name.to_s] ||= []) << handler).uniq!
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
queue_names
|
22
|
-
end
|
23
|
-
|
24
|
-
def use(handler)
|
25
|
-
proxy = handler.new
|
26
|
-
class << proxy
|
27
|
-
def to(queue_name)
|
28
|
-
((@@workers[queue_name.to_s] ||= []) << self.class).uniq!
|
29
|
-
end
|
30
|
-
end
|
31
|
-
proxy
|
32
|
-
end
|
33
|
-
|
34
|
-
def workers
|
35
|
-
@@workers
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
Cloudist.handle('make.sandwich', 'eat').with(SandwichMaker)
|
41
|
-
Cloudist.use(SandwichEater).to('eat.sandwich')
|
42
|
-
|
43
|
-
p Cloudist.workers
|
44
|
-
# >> {"eat"=>[SandwichMaker], "make.sandwich"=>[SandwichMaker], "eat.sandwich"=>[SandwichEater]}
|
data/examples/sandwich_client.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# Cloudst Example: Sandwich Client
|
2
|
-
#
|
3
|
-
# This example demonstrates dispatching a job to the worker and receiving event callbacks.
|
4
|
-
#
|
5
|
-
# Be sure to update the Cloudist connection settings if they differ from defaults:
|
6
|
-
# user: guest
|
7
|
-
# pass: guest
|
8
|
-
# port: 5672
|
9
|
-
# host: localhost
|
10
|
-
# vhost: /
|
11
|
-
#
|
12
|
-
$:.unshift File.dirname(__FILE__) + '/../lib'
|
13
|
-
require "rubygems"
|
14
|
-
require "cloudist"
|
15
|
-
|
16
|
-
Cloudist.signal_trap!
|
17
|
-
|
18
|
-
Cloudist.start {
|
19
|
-
|
20
|
-
log.info("Dispatching sandwich making job...")
|
21
|
-
|
22
|
-
unless ARGV.empty?
|
23
|
-
job_count = ARGV.pop.to_i
|
24
|
-
job_count.times { |i| enqueue('make.sandwich', {:bread => 'white', :sandwich_number => i})}
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
# enqueue('eat.sandwich', {:sandwich => job.id})
|
29
|
-
# enqueue('make.sandwich', {:bread => 'brown'})
|
30
|
-
|
31
|
-
# Listen to all sandwich jobs
|
32
|
-
listen('make.sandwich', 'eat.sandwich') {
|
33
|
-
everything {
|
34
|
-
Cloudist.log.info("#{headers[:message_type]} - Job ID: #{job_id}")
|
35
|
-
}
|
36
|
-
|
37
|
-
error { |e|
|
38
|
-
Cloudist.log.error(e.inspect)
|
39
|
-
Cloudist.log.error(e.backtrace.inspect)
|
40
|
-
Cloudist.stop
|
41
|
-
}
|
42
|
-
|
43
|
-
progress {
|
44
|
-
Cloudist.log.info("Progress: #{data[:progress]}")
|
45
|
-
}
|
46
|
-
|
47
|
-
event('started') {
|
48
|
-
Cloudist.log.info("Started making sandwich at #{Time.now.to_s}")
|
49
|
-
}
|
50
|
-
|
51
|
-
event('finished'){
|
52
|
-
Cloudist.log.info("Finished making sandwich at #{Time.now.to_s}")
|
53
|
-
Cloudist.stop
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
}
|
data/lib/cloudist/callback.rb
DELETED