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 CHANGED
@@ -6,10 +6,10 @@ desc 'Default: run tests.'
6
6
  task :default => [:test]
7
7
 
8
8
  desc 'Run tests.'
9
- Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
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.8
1
+ 0.10.9
@@ -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
- begin
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?)
@@ -11,10 +11,8 @@ module Refinery #:nodoc:
11
11
  queue_prefix = config['prefix'] || ''
12
12
  @server = server
13
13
  @thread = Thread.new do
14
- begin
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
@@ -26,10 +26,8 @@ module Refinery #:nodoc:
26
26
  def execute
27
27
  queue_prefix = config['prefix'] || ''
28
28
 
29
- begin
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}"
@@ -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
@@ -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
- @queue_provider ||= RightAws::SqsGen2.new(
27
- config['aws']['credentials']["access_key_id"],
28
- config['aws']['credentials']["secret_access_key"],
29
- {:multi_thread => true}
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.8"
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-11}
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"]
@@ -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
- Refinery::Daemon.any_instance.stubs(:require).with('java').raises(LoadError)
13
- Refinery::Daemon.any_instance.stubs(:queue).with(
14
- 'sample_waiting').returns(@waiting_queue)
15
- Refinery::Daemon.any_instance.stubs(:queue).with(
16
- 'sample_error').returns(@error_queue)
17
- Refinery::Daemon.any_instance.stubs(:queue).with(
18
- 'sample_done').returns(@done_queue)
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.expects(:receive).with(600)
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
- Refinery::Daemon.any_instance.expects(:queue).with(
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
@@ -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
- queue_provider = stub('queue provider')
13
- queue_provider.expects(:queue).with('heartbeat').returns(heartbeat_queue)
14
- RightAws::SqsGen2.stubs(:new).with(
15
- 'aki', 'sak', {:multi_thread => true}
16
- ).returns(queue_provider)
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)
@@ -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
- Refinery::Daemon.any_instance.stubs(:require).with('java').raises(LoadError)
17
- Refinery::Daemon.any_instance.stubs(:queue).with(
18
- 'sample_waiting').returns(@waiting_queue)
19
- Refinery::Daemon.any_instance.stubs(:queue).with(
20
- 'sample_error').returns(@error_queue)
21
- Refinery::Daemon.any_instance.stubs(:queue).with(
22
- 'sample_done').returns(@done_queue)
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
@@ -11,11 +11,13 @@ class QueueableTest < Test::Unit::TestCase
11
11
  setup_default_config
12
12
 
13
13
  queue = stub('queue')
14
- queue_provider = stub('queue provider')
15
- queue_provider.expects(:queue).with('a_queue').returns(queue)
16
- RightAws::SqsGen2.expects(:new).with(
17
- 'aki', 'sak', {:multi_thread => true}
18
- ).returns(queue_provider)
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')
@@ -20,7 +20,7 @@ class ServerTest < Test::Unit::TestCase
20
20
  should "be runnable" do
21
21
  setup_default_config
22
22
 
23
- Refinery::Heartbeat.expects(:new)
23
+ #Refinery::Heartbeat.expects(:new)
24
24
 
25
25
  assert_nothing_raised do
26
26
  thread = Thread.new do
@@ -1,41 +1,44 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class StatisticsTest < Test::Unit::TestCase
4
- context "a statistics instance" do
5
- should "record a done message" do
6
- dataset = stub('dataset')
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
- db = stub('db')
10
- db.stubs(:table_exists?).returns(true)
11
- db.stubs(:[]).with(:completed_jobs).returns(dataset)
8
+ dataset = stub('dataset')
9
+ dataset.expects(:<<) # TODO: improve this expectation
12
10
 
13
- Sequel.expects(:connect).with('sqlite://stats.db').returns(db)
11
+ db = stub('db')
12
+ db.stubs(:table_exists?).returns(true)
13
+ db.stubs(:[]).with(:completed_jobs).returns(dataset)
14
14
 
15
- message = {
16
- 'host_info' => {'hostname' => 'test', 'pid' => 1},
17
- 'run_time' => 1,
18
- 'original' => ''
19
- }
20
- Refinery::Statistics.new.record_done(message)
21
- end
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
- should "record an error message" do
24
- dataset = stub('dataset')
25
- dataset.expects(:<<) # TODO: improve this expectation
25
+ should "record an error message" do
26
+ dataset = stub('dataset')
27
+ dataset.expects(:<<) # TODO: improve this expectation
26
28
 
27
- db = stub('db')
28
- db.stubs(:table_exists?).returns(true)
29
- db.stubs(:[]).with(:errors).returns(dataset)
29
+ db = stub('db')
30
+ db.stubs(:table_exists?).returns(true)
31
+ db.stubs(:[]).with(:errors).returns(dataset)
30
32
 
31
- Sequel.expects(:connect).with('sqlite://stats.db').returns(db)
33
+ Sequel.expects(:connect).with('sqlite://stats.db').returns(db)
32
34
 
33
- message = {
34
- 'host_info' => {'hostname' => 'test', 'pid' => 1},
35
- 'error' => {'class' => 'Error', 'message' => 'An error occurred.'},
36
- 'original' => ''
37
- }
38
- Refinery::Statistics.new.record_error(message)
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.8
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-11 00:00:00 -10:00
12
+ date: 2009-08-12 00:00:00 -10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15