refinery 0.10.11 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/refinery.rb +6 -0
- data/lib/refinery/beanstalk_queue.rb +36 -0
- data/lib/refinery/beanstalk_queue_provider.rb +18 -0
- data/lib/refinery/queueable.rb +16 -11
- data/refinery.gemspec +10 -5
- metadata +8 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.11.0
|
data/lib/refinery.rb
CHANGED
@@ -48,6 +48,8 @@ module Refinery
|
|
48
48
|
if require_optional_library('java', 'JRuby')
|
49
49
|
require_optional_library('typica', 'JRuby Typica wrapper')
|
50
50
|
end
|
51
|
+
|
52
|
+
require_optional_library('beanstalk-client', 'Beanstalk Client')
|
51
53
|
end
|
52
54
|
|
53
55
|
# Require internal code files
|
@@ -74,6 +76,10 @@ module Refinery
|
|
74
76
|
require 'refinery/statistics'
|
75
77
|
require 'refinery/stats_server'
|
76
78
|
|
79
|
+
if defined?(Beanstalk)
|
80
|
+
require 'refinery/beanstalk_queue'
|
81
|
+
require 'refinery/beanstalk_queue_provider'
|
82
|
+
end
|
77
83
|
end
|
78
84
|
|
79
85
|
# Raised if a source file cannot be loaded
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Refinery #:nodoc:
|
2
|
+
# An interface to beanstalk using SQS-compatible methods.
|
3
|
+
class BeanstalkQueue
|
4
|
+
include Refinery::Loggable
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
# Construct a BeanstalkQueue instance.
|
8
|
+
#
|
9
|
+
# *<tt>name</tt>: if specified then that "tube" will be used.
|
10
|
+
# *<tt>host</tt>: if specified then those host:port combos will be used.
|
11
|
+
def initialize(name=nil, hosts=nil)
|
12
|
+
@name = name.gsub(/_/, '-') # beanstalk does not like underscores in tube names
|
13
|
+
@hosts = hosts || ['localhost:11300']
|
14
|
+
end
|
15
|
+
|
16
|
+
# Get the next message from the queue
|
17
|
+
def receive(visibility=nil)
|
18
|
+
beanstalk.reserve(visibility)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get the approximate queue size
|
22
|
+
def size
|
23
|
+
beanstalk.stats_tube(name)['current-jobs-ready']
|
24
|
+
end
|
25
|
+
|
26
|
+
# Send a message
|
27
|
+
def send_message(message)
|
28
|
+
beanstalk.put(message)
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def beanstalk
|
33
|
+
@beanstalk ||= Beanstalk::Pool.new(@hosts, name)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Refinery #:nodoc:
|
2
|
+
# A queue provider for beanstalk
|
3
|
+
class BeanstalkQueueProvider
|
4
|
+
include Refinery::Loggable
|
5
|
+
|
6
|
+
attr_reader :queues
|
7
|
+
|
8
|
+
# Initialize the queue provider
|
9
|
+
def initialize(hosts=nil)
|
10
|
+
@hosts = hosts
|
11
|
+
@queues = {}
|
12
|
+
end
|
13
|
+
# Get the named queue
|
14
|
+
def queue(name)
|
15
|
+
queues[name] ||= Refinery::BeanstalkQueue.new(name, @hosts)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/refinery/queueable.rb
CHANGED
@@ -14,7 +14,8 @@ module Refinery #:nodoc:
|
|
14
14
|
begin
|
15
15
|
yield queue(name)
|
16
16
|
rescue Exception => e
|
17
|
-
logger.error "An error occurred when communicating with queue #{name}: #{e}"
|
17
|
+
logger.error "An error occurred when communicating with queue #{name}: #{e.message}"
|
18
|
+
puts e.backtrace.map { |t| "\t#{t}" }.join("\n")
|
18
19
|
sleep(30)
|
19
20
|
end
|
20
21
|
end
|
@@ -23,17 +24,21 @@ module Refinery #:nodoc:
|
|
23
24
|
# Get the queue provider. Defaults to RightAws::SqsGen2 running
|
24
25
|
# in multi-thread mode.
|
25
26
|
def queue_provider
|
26
|
-
if defined?(
|
27
|
-
@queue_provider ||=
|
28
|
-
config['aws']['credentials']["access_key_id"],
|
29
|
-
config['aws']['credentials']["secret_access_key"]
|
30
|
-
)
|
27
|
+
if config['queue_engine'] == 'beanstalk' && defined?(Beanstalk)
|
28
|
+
@queue_provider ||= Refinery::BeanstalkQueueProvider.new
|
31
29
|
else
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
if defined?(Typica)
|
31
|
+
@queue_provider ||= Typica::Sqs::QueueService.new(
|
32
|
+
config['aws']['credentials']["access_key_id"],
|
33
|
+
config['aws']['credentials']["secret_access_key"]
|
34
|
+
)
|
35
|
+
else
|
36
|
+
@queue_provider ||= RightAws::SqsGen2.new(
|
37
|
+
config['aws']['credentials']["access_key_id"],
|
38
|
+
config['aws']['credentials']["secret_access_key"],
|
39
|
+
{:multi_thread => true}
|
40
|
+
)
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
data/refinery.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{refinery}
|
5
|
-
s.version = "0.
|
8
|
+
s.version = "0.11.0"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["Anthony Eden"]
|
9
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-11-11}
|
10
13
|
s.description = %q{Process data in a distributed fashion.}
|
11
14
|
s.email = %q{anthonyeden@gmail.com}
|
12
15
|
s.executables = ["epub", "monitor", "pubnow", "refinery"]
|
@@ -29,6 +32,8 @@ Gem::Specification.new do |s|
|
|
29
32
|
"bin/refinery",
|
30
33
|
"config/config.example.yml",
|
31
34
|
"lib/refinery.rb",
|
35
|
+
"lib/refinery/beanstalk_queue.rb",
|
36
|
+
"lib/refinery/beanstalk_queue_provider.rb",
|
32
37
|
"lib/refinery/config.rb",
|
33
38
|
"lib/refinery/configurable.rb",
|
34
39
|
"lib/refinery/daemon.rb",
|
@@ -70,12 +75,11 @@ Gem::Specification.new do |s|
|
|
70
75
|
"workers/sample.rb",
|
71
76
|
"workers/sleep.rb"
|
72
77
|
]
|
73
|
-
s.has_rdoc = true
|
74
78
|
s.homepage = %q{http://github.com/aeden/refinery}
|
75
79
|
s.rdoc_options = ["--charset=UTF-8"]
|
76
80
|
s.require_paths = ["lib"]
|
77
81
|
s.rubyforge_project = %q{refinery}
|
78
|
-
s.rubygems_version = %q{1.3.
|
82
|
+
s.rubygems_version = %q{1.3.5}
|
79
83
|
s.summary = %q{Refinery processes data in a distributed environment.}
|
80
84
|
s.test_files = [
|
81
85
|
"test/test_helper.rb",
|
@@ -97,7 +101,7 @@ Gem::Specification.new do |s|
|
|
97
101
|
|
98
102
|
if s.respond_to? :specification_version then
|
99
103
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
100
|
-
s.specification_version =
|
104
|
+
s.specification_version = 3
|
101
105
|
|
102
106
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
103
107
|
s.add_runtime_dependency(%q<right_aws>, [">= 0"])
|
@@ -114,3 +118,4 @@ Gem::Specification.new do |s|
|
|
114
118
|
s.add_dependency(%q<addressable>, [">= 0"])
|
115
119
|
end
|
116
120
|
end
|
121
|
+
|
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.
|
4
|
+
version: 0.11.0
|
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-
|
12
|
+
date: 2009-11-11 00:00:00 -10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -69,6 +69,8 @@ files:
|
|
69
69
|
- bin/refinery
|
70
70
|
- config/config.example.yml
|
71
71
|
- lib/refinery.rb
|
72
|
+
- lib/refinery/beanstalk_queue.rb
|
73
|
+
- lib/refinery/beanstalk_queue_provider.rb
|
72
74
|
- lib/refinery/config.rb
|
73
75
|
- lib/refinery/configurable.rb
|
74
76
|
- lib/refinery/daemon.rb
|
@@ -111,6 +113,8 @@ files:
|
|
111
113
|
- workers/sleep.rb
|
112
114
|
has_rdoc: true
|
113
115
|
homepage: http://github.com/aeden/refinery
|
116
|
+
licenses: []
|
117
|
+
|
114
118
|
post_install_message:
|
115
119
|
rdoc_options:
|
116
120
|
- --charset=UTF-8
|
@@ -131,9 +135,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
135
|
requirements: []
|
132
136
|
|
133
137
|
rubyforge_project: refinery
|
134
|
-
rubygems_version: 1.3.
|
138
|
+
rubygems_version: 1.3.5
|
135
139
|
signing_key:
|
136
|
-
specification_version:
|
140
|
+
specification_version: 3
|
137
141
|
summary: Refinery processes data in a distributed environment.
|
138
142
|
test_files:
|
139
143
|
- test/test_helper.rb
|