cloudist 0.2.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/Gemfile +15 -11
  2. data/Gemfile.lock +20 -7
  3. data/README.md +61 -39
  4. data/VERSION +1 -1
  5. data/cloudist.gemspec +50 -16
  6. data/examples/amqp/Gemfile +3 -0
  7. data/examples/amqp/Gemfile.lock +12 -0
  8. data/examples/amqp/amqp_consumer.rb +56 -0
  9. data/examples/amqp/amqp_publisher.rb +50 -0
  10. data/examples/queue_message.rb +7 -7
  11. data/examples/sandwich_client_with_custom_listener.rb +77 -0
  12. data/examples/sandwich_worker_with_class.rb +22 -7
  13. data/lib/cloudist.rb +113 -56
  14. data/lib/cloudist/application.rb +60 -0
  15. data/lib/cloudist/core_ext/class.rb +139 -0
  16. data/lib/cloudist/core_ext/kernel.rb +13 -0
  17. data/lib/cloudist/core_ext/module.rb +11 -0
  18. data/lib/cloudist/encoding.rb +13 -0
  19. data/lib/cloudist/errors.rb +2 -0
  20. data/lib/cloudist/job.rb +21 -18
  21. data/lib/cloudist/listener.rb +108 -54
  22. data/lib/cloudist/message.rb +97 -0
  23. data/lib/cloudist/messaging.rb +29 -0
  24. data/lib/cloudist/payload.rb +45 -105
  25. data/lib/cloudist/payload_old.rb +155 -0
  26. data/lib/cloudist/publisher.rb +7 -2
  27. data/lib/cloudist/queue.rb +152 -0
  28. data/lib/cloudist/queues/basic_queue.rb +83 -53
  29. data/lib/cloudist/queues/job_queue.rb +13 -24
  30. data/lib/cloudist/queues/reply_queue.rb +13 -21
  31. data/lib/cloudist/request.rb +33 -7
  32. data/lib/cloudist/worker.rb +9 -2
  33. data/lib/cloudist_old.rb +300 -0
  34. data/lib/em/em_timer_utils.rb +55 -0
  35. data/lib/em/iterator.rb +27 -0
  36. data/spec/cloudist/message_spec.rb +91 -0
  37. data/spec/cloudist/messaging_spec.rb +19 -0
  38. data/spec/cloudist/payload_spec.rb +10 -4
  39. data/spec/cloudist/payload_spec_2_spec.rb +78 -0
  40. data/spec/cloudist/queue_spec.rb +16 -0
  41. data/spec/cloudist_spec.rb +49 -45
  42. data/spec/spec_helper.rb +0 -1
  43. data/spec/support/amqp.rb +16 -0
  44. metadata +112 -102
  45. data/examples/extending_values.rb +0 -44
  46. data/examples/sandwich_client.rb +0 -57
  47. data/lib/cloudist/callback.rb +0 -16
  48. data/lib/cloudist/callback_methods.rb +0 -19
  49. 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]}
@@ -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
- }
@@ -1,16 +0,0 @@
1
- module Cloudist
2
- class Callback
3
- include Cloudist::CallbackMethods
4
-
5
- attr_reader :payload, :source
6
-
7
- def initialize(source)
8
- @source = source
9
- end
10
-
11
- def call(payload)
12
- @payload = payload
13
- instance_eval(&source)
14
- end
15
- end
16
- end
@@ -1,19 +0,0 @@
1
- module Cloudist
2
- module CallbackMethods
3
- def data
4
- payload.body
5
- end
6
-
7
- def headers
8
- payload.headers
9
- end
10
-
11
- def job_id
12
- headers[:message_id]
13
- end
14
-
15
- def runtime
16
-
17
- end
18
- end
19
- end
@@ -1,14 +0,0 @@
1
- module Cloudist
2
- class ErrorCallback < Callback
3
- def call(payload)
4
- @payload = payload
5
-
6
- case source.arity
7
- when 1
8
- instance_exec(payload.exception, &source)
9
- else
10
- instance_exec(&source)
11
- end
12
- end
13
- end
14
- end