cloudq_client 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/cloudq/connection.rb +9 -1
- data/lib/cloudq/consume.rb +1 -1
- data/lib/cloudq/publish.rb +7 -3
- data/lib/cloudq/version.rb +1 -1
- data/lib/cloudq/worker.rb +29 -0
- data/lib/cloudq.rb +1 -1
- data/readme.md +35 -37
- metadata +4 -3
data/lib/cloudq/connection.rb
CHANGED
data/lib/cloudq/consume.rb
CHANGED
data/lib/cloudq/publish.rb
CHANGED
@@ -4,17 +4,21 @@ require 'json'
|
|
4
4
|
module Cloudq
|
5
5
|
class Publish < Base
|
6
6
|
def job(klass, *args)
|
7
|
-
|
7
|
+
jsonized_job = jsonize(:job => { :klass => klass, :args => args})
|
8
|
+
post(jsonized_job)
|
8
9
|
end
|
9
10
|
|
10
11
|
private
|
11
|
-
def post(
|
12
|
+
def post(data)
|
12
13
|
headers = {:content_type => :json, :accept => :json}
|
13
|
-
RestClient.post [Cloudq::Connection.url, @queue].join('/'),
|
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
|
data/lib/cloudq/version.rb
CHANGED
@@ -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
data/readme.md
CHANGED
@@ -1,56 +1,54 @@
|
|
1
1
|
# Cloudq Client
|
2
2
|
|
3
|
-
|
4
|
-
modules.
|
3
|
+
(In Development Mode)
|
5
4
|
|
6
|
-
##
|
5
|
+
## What is it?
|
7
6
|
|
8
|
-
|
9
|
-
|
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
|
-
|
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
|
-
|
13
|
+
For more information on the cloudq protocol see [http://cloudq.heroku.com](http://cloudq.heroku.com)
|
18
14
|
|
19
|
-
|
15
|
+
## Requirements
|
20
16
|
|
21
|
-
|
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
|
-
|
24
|
-
|
21
|
+
* Ruby 1.9
|
22
|
+
* RubyGems
|
25
23
|
|
26
|
-
|
24
|
+
And the Cloudq Gem depends on the rest-client gem, but it should install when you install the gem.
|
27
25
|
|
28
|
-
|
29
|
-
# You must require the files that have the Job you need to perform
|
26
|
+
## Install
|
30
27
|
|
31
|
-
|
28
|
+
gem install cloudq_client
|
32
29
|
|
33
|
-
|
30
|
+
## How do I publish a job?
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
42
|
+
## How do I create a worker?
|
50
43
|
|
51
|
-
|
52
|
-
|
53
|
-
Cloudq::
|
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.
|
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-
|
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
|
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
|