newbamboo-job_queue 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/job_queue/adapters/stomp_adapter.rb +28 -0
- data/lib/job_queue.rb +1 -0
- data/spec/stomp_adapter_spec.rb +39 -0
- metadata +4 -1
data/VERSION.yml
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'stomp'
|
2
|
+
|
3
|
+
class JobQueue::StompAdapter
|
4
|
+
def initialize(options = {})
|
5
|
+
username = options[:username]
|
6
|
+
password = options[:password]
|
7
|
+
host = options[:host] || 'localhost'
|
8
|
+
port = options[:port] || 61613
|
9
|
+
@conn = Stomp::Connection.new(username, password, host, port, true)
|
10
|
+
end
|
11
|
+
|
12
|
+
def put(string)
|
13
|
+
@conn.send("/queue/job_queue", string, :persistent => true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def subscribe(error_report, &block)
|
17
|
+
@conn.subscribe("/queue/job_queue")
|
18
|
+
loop do
|
19
|
+
begin
|
20
|
+
job = @conn.receive
|
21
|
+
JobQueue.logger.info "Stomp received #{job}"
|
22
|
+
yield job.body
|
23
|
+
rescue => e
|
24
|
+
error_report.call(job, e)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/job_queue.rb
CHANGED
@@ -3,5 +3,6 @@ require 'job_queue/job_queue'
|
|
3
3
|
|
4
4
|
JobQueue.autoload 'AMQPAdapter', 'job_queue/adapters/amqp_adapter'
|
5
5
|
JobQueue.autoload 'BeanstalkAdapter', 'job_queue/adapters/beanstalk_adapter'
|
6
|
+
JobQueue.autoload 'StompAdapter', 'job_queue/adapters/stomp_adapter'
|
6
7
|
JobQueue.autoload 'TestAdapter', 'job_queue/adapters/test_adapter'
|
7
8
|
JobQueue.autoload 'VerboseAdapter', 'job_queue/adapters/verbose_adapter'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe JobQueue::TestAdapter do
|
4
|
+
before :all do
|
5
|
+
JobQueue.adapter = JobQueue::StompAdapter.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should write onto queue and fetch stuff back off" do
|
9
|
+
JobQueue.put("hello")
|
10
|
+
|
11
|
+
JobQueue.subscribe do |job|
|
12
|
+
@job = job
|
13
|
+
throw :stop
|
14
|
+
end
|
15
|
+
|
16
|
+
@job.should == "hello"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should pull items off in the order the were added" do
|
20
|
+
JobQueue.put("foo")
|
21
|
+
JobQueue.put("bar")
|
22
|
+
|
23
|
+
retrieved_jobs = []
|
24
|
+
|
25
|
+
begin
|
26
|
+
Timeout::timeout(0.5) do
|
27
|
+
JobQueue.subscribe do |job|
|
28
|
+
retrieved_jobs << job
|
29
|
+
end
|
30
|
+
end
|
31
|
+
rescue Timeout::Error
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
retrieved_jobs[0].should == "foo"
|
36
|
+
retrieved_jobs[1].should == "bar"
|
37
|
+
retrieved_jobs[2].should == nil
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newbamboo-job_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martyn Loughran
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/job_queue.rb
|
31
31
|
- lib/job_queue/adapters/amqp_adapter.rb
|
32
32
|
- lib/job_queue/adapters/beanstalk_adapter.rb
|
33
|
+
- lib/job_queue/adapters/stomp_adapter.rb
|
33
34
|
- lib/job_queue/adapters/test_adapter.rb
|
34
35
|
- lib/job_queue/adapters/verbose_adapter.rb
|
35
36
|
- lib/job_queue/job_queue.rb
|
@@ -38,6 +39,7 @@ files:
|
|
38
39
|
- spec/job_queue_spec.rb
|
39
40
|
- spec/spec_helper.rb
|
40
41
|
- spec/test_adapter_spec.rb
|
42
|
+
- spec/stomp_adapter_spec.rb
|
41
43
|
- spec/verbose_adapter_spec.rb
|
42
44
|
has_rdoc: true
|
43
45
|
homepage: http://github.com/mloughran/job_queue
|
@@ -71,4 +73,5 @@ test_files:
|
|
71
73
|
- spec/job_queue_spec.rb
|
72
74
|
- spec/spec_helper.rb
|
73
75
|
- spec/test_adapter_spec.rb
|
76
|
+
- spec/stomp_adapter_spec.rb
|
74
77
|
- spec/verbose_adapter_spec.rb
|