cloudq_client 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,15 @@ module Cloudq
2
2
  module Connection
3
3
  extend self
4
4
 
5
- attr_accessor :url
5
+ def url
6
+ @url
7
+ end
8
+
9
+ def url=(uri)
10
+ raise "Bad URL" unless uri =~ /^http/
11
+ @url = uri
12
+ end
13
+
6
14
  end
7
15
  end
8
16
 
@@ -10,7 +10,7 @@ module Cloudq
10
10
  private
11
11
  def perform(a_job)
12
12
  klass = Object.const_get(a_job["klass"])
13
- klass.perform(a_job["args"])
13
+ klass.perform(*a_job["args"])
14
14
  end
15
15
 
16
16
  def get(&block)
@@ -4,17 +4,21 @@ require 'json'
4
4
  module Cloudq
5
5
  class Publish < Base
6
6
  def job(klass, *args)
7
- post(:job => { :klass => klass, :args => args} )
7
+ jsonized_job = jsonize(:job => { :klass => klass, :args => args})
8
+ post(jsonized_job)
8
9
  end
9
10
 
10
11
  private
11
- def post(job)
12
+ def post(data)
12
13
  headers = {:content_type => :json, :accept => :json}
13
- RestClient.post [Cloudq::Connection.url, @queue].join('/'), job, headers do |response|
14
+ RestClient.post [Cloudq::Connection.url, @queue].join('/'), data, headers do |response|
14
15
  JSON.parse(response)['status'] == 'success'
15
16
  end
16
17
  end
17
18
 
19
+ def jsonize(data)
20
+ data.to_json
21
+ end
18
22
 
19
23
  end
20
24
  end
@@ -1,4 +1,4 @@
1
1
  module Cloudq
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
4
4
 
@@ -0,0 +1,29 @@
1
+ # Cloudq Client Worker
2
+
3
+ # A Worker is a process that subscribes to a queue and
4
+ # Processes Jobs from that queue
5
+ #
6
+ # This worker makes it super simple to subscribe to a queue
7
+
8
+ # Cloudq::Worker.new(:queue1, :queue2, :queue3).run do
9
+ # print '.'
10
+ # sleep 2
11
+ # end
12
+
13
+
14
+ module Cloudq
15
+ class Worker
16
+ attr_accessor :queues
17
+
18
+ def initialize(*args)
19
+ @queues = args
20
+ end
21
+
22
+ def run(&block)
23
+ loop do
24
+ @queues.each { |q| Consume.new(q).job }
25
+ yield
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/cloudq.rb CHANGED
@@ -5,4 +5,4 @@ require 'cloudq/connection'
5
5
  require 'cloudq/base'
6
6
  require 'cloudq/publish'
7
7
  require 'cloudq/consume'
8
-
8
+ require 'cloudq/worker'
data/readme.md CHANGED
@@ -1,56 +1,54 @@
1
1
  # Cloudq Client
2
2
 
3
- This is the Cloudq Client Gem, it has both the consumer and publisher
4
- modules.
3
+ (In Development Mode)
5
4
 
6
- ## The Job
5
+ ## What is it?
7
6
 
8
- The Job is the JSON message that is published to the queue server to be
9
- consumed by a worker. The queue server can have one to many queues and
10
- you can create one to many workers. With Cloudq you can have these
11
- workers all over the internet. The Cloudq server is a rack application
12
- so you can do awesome things with rack middleware to add authentication,
13
- encryption, logging, etc. All using Rack Middleware.
7
+ Cloudq is a job queue system that allows you to publish or subscribe to queues
8
+ anywhere in the cloud.
14
9
 
15
- The job message is simple: (It is a json object )
10
+ Cloudq_Client is a ruby implementation of the cloudq protocol that makes publishing jobs
11
+ and consuming jobs in ruby, very easy.
16
12
 
17
- { 'job': { 'klass': 'Archive', 'args': [1] }}
13
+ For more information on the cloudq protocol see [http://cloudq.heroku.com](http://cloudq.heroku.com)
18
14
 
19
- Args can be a hash or array.
15
+ ## Requirements
20
16
 
21
- ## The Consumer
17
+ You need a cloudq job server, if you do not have a cloudq job server to connect to, then you
18
+ need to set one up. If you do have a cloudq server, then for this client to work you need the
19
+ following:
22
20
 
23
- The consumer will reserve a job from the queue then perform the job and
24
- delete it from the queue.
21
+ * Ruby 1.9
22
+ * RubyGems
25
23
 
26
- ### Sample Consumer Worker
24
+ And the Cloudq Gem depends on the rest-client gem, but it should install when you install the gem.
27
25
 
28
- require 'cloudq/consume'
29
- # You must require the files that have the Job you need to perform
26
+ ## Install
30
27
 
31
- require 'donut/job'
28
+ gem install cloudq_client
32
29
 
33
- Cloudq::Connection.url = 'http://donuts.com'
30
+ ## How do I publish a job?
34
31
 
35
- loop do
36
- Cloudq::Consume.new(:make_the_donuts).job
37
- sleep 5
38
- end
39
-
40
- ## The Publisher
41
-
42
- The publisher will create a job on the queue, the great thing about the
43
- publisher, is that it does not have to know the klass or the job that
44
- you want your worker to perform. It just published the job on the
45
- queue.
32
+ require 'cloudq'
33
+
34
+ Cloudq::Connection.url = 'http://your.cloudq.server'
35
+
36
+ # Publish Job to a queue called - awesome
37
+
38
+ Cloudq::Publish(:awesome).job 'Awesome', :type => 'Sauce'
39
+
46
40
 
47
- ### Sample Publisher
48
41
 
49
- require 'cloudq/publish'
42
+ ## How do I create a worker?
50
43
 
51
- Cloudq::Connection.url = 'http://donuts.com'
52
-
53
- Cloudq::Publish.new(:make_donuts).job(:make_donuts, 'Bake', :type =>
54
- 'glazed')
44
+ require 'cloudq'
45
+
46
+ Cloudq::Connection.url = 'http://your.cloudq.server'
55
47
 
48
+ # Check Q every 5 seconds
49
+ Cloudq::Worker.new(:awesome).run do
50
+ print '.'
51
+ sleep 5
52
+ end
53
+
56
54
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cloudq_client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tom Wilson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-18 00:00:00 -04:00
13
+ date: 2011-04-21 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -35,7 +35,7 @@ dependencies:
35
35
  version: 1.6.1
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
- description: "The Cloudq will "
38
+ description: "The Cloudq Client gem is an awesome client interface to the cloudq a remote job queue engine that allows you to publish jobs and subscribe from jobs anywhere in the cloud.... "
39
39
  email:
40
40
  - tom@jackhq.com
41
41
  executables: []
@@ -50,6 +50,7 @@ files:
50
50
  - lib/cloudq/consume.rb
51
51
  - lib/cloudq/publish.rb
52
52
  - lib/cloudq/version.rb
53
+ - lib/cloudq/worker.rb
53
54
  - lib/cloudq.rb
54
55
  - LICENSE
55
56
  - readme.md