refinery 0.10.8 → 0.10.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/lib/refinery/daemon.rb +1 -3
- data/lib/refinery/heartbeat.rb +1 -3
- data/lib/refinery/processor.rb +1 -3
- data/lib/refinery/publisher.rb +1 -1
- data/lib/refinery/queueable.rb +12 -5
- data/lib/refinery.rb +7 -0
- data/refinery.gemspec +2 -2
- data/test/unit/daemon_test.rb +11 -9
- data/test/unit/heartbeat_test.rb +7 -5
- data/test/unit/processor_test.rb +9 -7
- data/test/unit/queueable_test.rb +7 -5
- data/test/unit/server_test.rb +1 -1
- data/test/unit/statistics_test.rb +32 -29
- metadata +2 -2
data/Rakefile
CHANGED
@@ -6,10 +6,10 @@ desc 'Default: run tests.'
|
|
6
6
|
task :default => [:test]
|
7
7
|
|
8
8
|
desc 'Run tests.'
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
task :test do
|
10
|
+
Dir.glob('test/**/*_test.rb') do |f|
|
11
|
+
require f
|
12
|
+
end
|
13
13
|
end
|
14
14
|
|
15
15
|
desc 'Generate documentation.'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.10.
|
1
|
+
0.10.9
|
data/lib/refinery/daemon.rb
CHANGED
@@ -74,10 +74,8 @@ module Refinery #:nodoc:
|
|
74
74
|
def execute
|
75
75
|
logger.debug "Running daemon thread: #{name} (settings: #{settings.inspect})"
|
76
76
|
|
77
|
-
|
78
|
-
require 'java'
|
77
|
+
if defined?(java.lang.Thread)
|
79
78
|
java.lang.Thread.current_thread.name = "#{name} Daemon"
|
80
|
-
rescue LoadError => e
|
81
79
|
end
|
82
80
|
|
83
81
|
while(running?)
|
data/lib/refinery/heartbeat.rb
CHANGED
@@ -11,10 +11,8 @@ module Refinery #:nodoc:
|
|
11
11
|
queue_prefix = config['prefix'] || ''
|
12
12
|
@server = server
|
13
13
|
@thread = Thread.new do
|
14
|
-
|
15
|
-
require 'java'
|
14
|
+
if defined?(java.lang.Thread)
|
16
15
|
java.lang.Thread.current_thread.name = 'Heartbeat'
|
17
|
-
rescue Exception => e
|
18
16
|
end
|
19
17
|
|
20
18
|
loop do
|
data/lib/refinery/processor.rb
CHANGED
@@ -26,10 +26,8 @@ module Refinery #:nodoc:
|
|
26
26
|
def execute
|
27
27
|
queue_prefix = config['prefix'] || ''
|
28
28
|
|
29
|
-
|
30
|
-
require 'java'
|
29
|
+
if defined?(java.lang.Thread)
|
31
30
|
java.lang.Thread.current_thread.name = "#{key} Processor"
|
32
|
-
rescue Exception => e
|
33
31
|
end
|
34
32
|
|
35
33
|
logger.debug "Creating daemons for #{key}"
|
data/lib/refinery/publisher.rb
CHANGED
@@ -35,7 +35,7 @@ module Refinery #:nodoc:
|
|
35
35
|
# Publish the given message to the queue. The message will be converted
|
36
36
|
# to JSON and pushed into the queue associated with the publisher.
|
37
37
|
def publish_to_queue(queue, message)
|
38
|
-
logger.debug "Publisher #{self.class.name} sending message: #{message.to_json}"
|
38
|
+
logger.debug "Publisher #{self.class.name} sending message: #{message.to_json} to queue #{queue.url}"
|
39
39
|
queue.send_message(Base64.encode64(message.to_json))
|
40
40
|
end
|
41
41
|
end
|
data/lib/refinery/queueable.rb
CHANGED
@@ -23,11 +23,18 @@ module Refinery #:nodoc:
|
|
23
23
|
# Get the queue provider. Defaults to RightAws::SqsGen2 running
|
24
24
|
# in multi-thread mode.
|
25
25
|
def queue_provider
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
if defined?(Typica)
|
27
|
+
@queue_provider ||= Typica::Sqs::QueueService.new(
|
28
|
+
config['aws']['credentials']["access_key_id"],
|
29
|
+
config['aws']['credentials']["secret_access_key"]
|
30
|
+
)
|
31
|
+
else
|
32
|
+
@queue_provider ||= RightAws::SqsGen2.new(
|
33
|
+
config['aws']['credentials']["access_key_id"],
|
34
|
+
config['aws']['credentials']["secret_access_key"],
|
35
|
+
{:multi_thread => true}
|
36
|
+
)
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
data/lib/refinery.rb
CHANGED
@@ -34,13 +34,20 @@ module Refinery
|
|
34
34
|
def self.require_optional_library(short_name, display_name)
|
35
35
|
begin
|
36
36
|
require short_name
|
37
|
+
puts "#{short_name} optional library was loaded"
|
38
|
+
true
|
37
39
|
rescue LoadError
|
40
|
+
puts "#{short_name} optional library not loaded"
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
41
44
|
def self.require_optional_libraries
|
42
45
|
require_optional_library('sequel', 'Sequel gem')
|
43
46
|
require_optional_library('ramaze', 'Ramaze')
|
47
|
+
|
48
|
+
if require_optional_library('java', 'JRuby')
|
49
|
+
require_optional_library('typica', 'JRuby Typica wrapper')
|
50
|
+
end
|
44
51
|
end
|
45
52
|
|
46
53
|
# Require internal code files
|
data/refinery.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{refinery}
|
5
|
-
s.version = "0.10.
|
5
|
+
s.version = "0.10.9"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Anthony Eden"]
|
9
|
-
s.date = %q{2009-08-
|
9
|
+
s.date = %q{2009-08-12}
|
10
10
|
s.description = %q{Process data in a distributed fashion.}
|
11
11
|
s.email = %q{anthonyeden@gmail.com}
|
12
12
|
s.executables = ["epub", "monitor", "pubnow", "refinery"]
|
data/test/unit/daemon_test.rb
CHANGED
@@ -9,13 +9,15 @@ class DaemonTest < Test::Unit::TestCase
|
|
9
9
|
@error_queue = stub('Queue(error)')
|
10
10
|
@done_queue = stub('Queue(done)')
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
'
|
12
|
+
@provider = stub('QueueProvider')
|
13
|
+
if defined?(Typica)
|
14
|
+
Typica::Sqs::QueueService.stubs(:new).returns(@provider)
|
15
|
+
else
|
16
|
+
RightAws::SqsGen2.stubs(:new).returns(@provider)
|
17
|
+
end
|
18
|
+
@provider.stubs(:queue).with('sample_waiting').returns(@waiting_queue)
|
19
|
+
@provider.stubs(:queue).with('sample_error').returns(@error_queue)
|
20
|
+
@provider.stubs(:queue).with('sample_done').returns(@done_queue)
|
19
21
|
end
|
20
22
|
should "be startable" do
|
21
23
|
@waiting_queue.stubs(:receive)
|
@@ -29,12 +31,12 @@ class DaemonTest < Test::Unit::TestCase
|
|
29
31
|
assert_not_nil daemon.logger
|
30
32
|
end
|
31
33
|
should "allow visibility setting" do
|
32
|
-
@waiting_queue.
|
34
|
+
@waiting_queue.stubs(:receive).with(600)
|
33
35
|
daemon = Refinery::Daemon.new(@processor, 'sample', '', {'visibility' => 600})
|
34
36
|
end
|
35
37
|
should "have a queue name" do
|
36
38
|
@waiting_queue.stubs(:receive)
|
37
|
-
|
39
|
+
@provider.stubs(:queue).with(
|
38
40
|
'prefix_sample_waiting').returns(@waiting_queue)
|
39
41
|
daemon = Refinery::Daemon.new(@processor, 'sample', 'prefix_')
|
40
42
|
assert_equal 'prefix_sample', daemon.queue_name
|
data/test/unit/heartbeat_test.rb
CHANGED
@@ -9,11 +9,13 @@ class HeartbeatTest < Test::Unit::TestCase
|
|
9
9
|
|
10
10
|
heartbeat_queue = stub('heartbeat queue')
|
11
11
|
heartbeat_queue.stubs(:send_message)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
provider = stub('queue provider')
|
13
|
+
provider.stubs(:queue).with('heartbeat').returns(heartbeat_queue)
|
14
|
+
if defined?(Typica)
|
15
|
+
Typica::Sqs::QueueService.stubs(:new).returns(provider)
|
16
|
+
else
|
17
|
+
RightAws::SqsGen2.stubs(:new).returns(provider)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
should "be initializable" do
|
19
21
|
Refinery::Heartbeat.new(@server)
|
data/test/unit/processor_test.rb
CHANGED
@@ -13,13 +13,15 @@ class ProcessorTest < Test::Unit::TestCase
|
|
13
13
|
@error_queue = stub('Queue(error)')
|
14
14
|
@done_queue = stub('Queue(done)')
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
'
|
16
|
+
provider = stub('QueueProvider')
|
17
|
+
if defined?(Typica)
|
18
|
+
Typica::Sqs::QueueService.stubs(:new).returns(provider)
|
19
|
+
else
|
20
|
+
RightAws::SqsGen2.stubs(:new).returns(provider)
|
21
|
+
end
|
22
|
+
provider.stubs(:queue).with('sample_waiting').returns(@waiting_queue)
|
23
|
+
provider.stubs(:queue).with('sample_error').returns(@error_queue)
|
24
|
+
provider.stubs(:queue).with('sample_done').returns(@done_queue)
|
23
25
|
end
|
24
26
|
should "initialize" do
|
25
27
|
assert_nothing_raised do
|
data/test/unit/queueable_test.rb
CHANGED
@@ -11,11 +11,13 @@ class QueueableTest < Test::Unit::TestCase
|
|
11
11
|
setup_default_config
|
12
12
|
|
13
13
|
queue = stub('queue')
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
provider = stub('queue provider')
|
15
|
+
provider.expects(:queue).with('a_queue').returns(queue)
|
16
|
+
if defined?(Typica)
|
17
|
+
Typica::Sqs::QueueService.expects(:new).returns(provider)
|
18
|
+
else
|
19
|
+
RightAws::SqsGen2.expects(:new).with('aki', 'sak', {:multi_thread => true}).returns(provider)
|
20
|
+
end
|
19
21
|
|
20
22
|
queueable = QueueMe.new
|
21
23
|
assert_not_nil queueable.queue('a_queue')
|
data/test/unit/server_test.rb
CHANGED
@@ -1,41 +1,44 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
dataset.expects(:<<) # TODO: improve this expectation
|
3
|
+
if defined?(Sequel)
|
4
|
+
class StatisticsTest < Test::Unit::TestCase
|
5
|
+
context "a statistics instance" do
|
6
|
+
should "record a done message" do
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
db.stubs(:[]).with(:completed_jobs).returns(dataset)
|
8
|
+
dataset = stub('dataset')
|
9
|
+
dataset.expects(:<<) # TODO: improve this expectation
|
12
10
|
|
13
|
-
|
11
|
+
db = stub('db')
|
12
|
+
db.stubs(:table_exists?).returns(true)
|
13
|
+
db.stubs(:[]).with(:completed_jobs).returns(dataset)
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
Sequel.expects(:connect).with('sqlite://stats.db').returns(db)
|
16
|
+
|
17
|
+
message = {
|
18
|
+
'host_info' => {'hostname' => 'test', 'pid' => 1},
|
19
|
+
'run_time' => 1,
|
20
|
+
'original' => ''
|
21
|
+
}
|
22
|
+
Refinery::Statistics.new.record_done(message)
|
23
|
+
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
should "record an error message" do
|
26
|
+
dataset = stub('dataset')
|
27
|
+
dataset.expects(:<<) # TODO: improve this expectation
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
db = stub('db')
|
30
|
+
db.stubs(:table_exists?).returns(true)
|
31
|
+
db.stubs(:[]).with(:errors).returns(dataset)
|
30
32
|
|
31
|
-
|
33
|
+
Sequel.expects(:connect).with('sqlite://stats.db').returns(db)
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
message = {
|
36
|
+
'host_info' => {'hostname' => 'test', 'pid' => 1},
|
37
|
+
'error' => {'class' => 'Error', 'message' => 'An error occurred.'},
|
38
|
+
'original' => ''
|
39
|
+
}
|
40
|
+
Refinery::Statistics.new.record_error(message)
|
41
|
+
end
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refinery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Eden
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-12 00:00:00 -10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|