Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 4 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
2 examples/configuration.rb
@@ -4,7 +4,7 @@
require 'json'
RabbitJobs.configure do |c|
- c.host "127.0.0.1"
+ c.url "amqp://localhost"
c.exchange 'test_exchange', durable: true, auto_delete: false
View
2 lib/rabbit_jobs/amqp_helpers.rb
@@ -15,7 +15,7 @@ def amqp_with_exchange(&block)
block.call(connection, exchange)
else
- AMQP.start(host: RJ.config.host) do |connection|
+ AMQP.start(RJ.config.url) do |connection|
channel = AMQP::Channel.new(connection)
View
43 lib/rabbit_jobs/configuration.rb
@@ -15,11 +15,22 @@ def config
end
def load_config
- self.configure do |c|
- c.host 'localhost'
- c.exchange 'rabbit_jobs', auto_delete: false, durable: true
- c.queue 'default', auto_delete: false, ack: true, durable: true
+ if defined?(Rails) && Rails.respond_to?(:root)
+ config_file = Rails.root.join('config/rabbit_jobs.yml')
+ if File.exists?(config_file)
+ @@configuration ||= Configuration.new
+ @@configuration.load_file(config_file)
+ end
+ end
+
+ unless @@configuration
+ self.configure do |c|
+ c.url 'amqp://localhost'
+ c.exchange 'rabbit_jobs', auto_delete: false, durable: true
+ c.queue 'default', auto_delete: false, ack: true, durable: true
+ end
end
+
@@configuration
end
@@ -50,7 +61,7 @@ def to_hash
def initialize
@data = {
error_log: true,
- host: 'localhost',
+ url: 'amqp://localhost',
exchange: 'rabbit_jobs',
exchange_params: DEFAULT_EXCHANGE_PARAMS,
queues: {}
@@ -70,8 +81,12 @@ def mail_errors_to(email = nil, from_email = nil)
end
end
- def mail_errors_from
- @data[:mail_errors_form]
+ def mail_errors_from(email = nil)
+ if email
+ @data[:mail_errors_from] = email
+ else
+ @data[:mail_errors_from]
+ end
end
def error_log
@@ -82,12 +97,12 @@ def disable_error_log
@data[:error_log] = false
end
- def host(value = nil)
+ def url(value = nil)
if value
raise ArgumentError unless value.is_a?(String) && value != ""
- @data[:host] = value.to_s
+ @data[:url] = value.to_s
else
- @data[:host]
+ @data[:url]
end
end
@@ -133,9 +148,13 @@ def load_yaml(text)
def convert_yaml_config(yaml)
if yaml['rabbit_jobs']
convert_yaml_config(yaml['rabbit_jobs'])
+ elsif defined?(Rails) && yaml[Rails.env.to_s]
+ convert_yaml_config(yaml[Rails.env.to_s])
else
- @data = {host: nil, exchange: nil, queues: {}}
- host yaml['host']
+ @data = {url: nil, exchange: nil, queues: {}}
+ %w(url exchange mail_errors_to mail_errors_from).each do |m|
+ self.send(m, yaml[m])
+ end
exchange yaml['exchange'], symbolize_keys!(yaml['exchange_params'])
yaml['queues'].each do |name, params|
queue name, symbolize_keys!(params) || {}
View
2 lib/rabbit_jobs/publisher.rb
@@ -59,7 +59,7 @@ def purge_queue(*routing_keys)
def self.with_bunny(&block)
raise ArgumentError unless block
- Bunny.run(host: RJ.config.host, logging: false) do |bunny|
+ Bunny.run(url: RJ.config.url, logging: false) do |bunny|
block.call(bunny)
end
end
View
8 lib/rabbit_jobs/tasks.rb
@@ -14,10 +14,8 @@ def initialize_rj_daemon(daemon)
daemon
end
- task :setup
-
desc "Start a Rabbit Jobs worker"
- task :worker => [ :preload, :setup ] do
+ task :worker => :environment do
require 'rabbit_jobs'
queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',')
@@ -27,14 +25,14 @@ def initialize_rj_daemon(daemon)
end
desc "Start a Rabbit Jobs scheduler"
- task :scheduler => [ :preload, :setup ] do
+ task :scheduler => :environment do
scheduler = initialize_rj_daemon(RabbitJobs::Scheduler.new)
scheduler.work
end
# Preload app files if this is Rails
- task :preload => :setup do
+ task :environment do
if defined?(Rails) && Rails.respond_to?(:application)
# Rails 3
# Rails.application.eager_load!
View
2 lib/rabbit_jobs/version.rb
@@ -1,3 +1,3 @@
module RabbitJobs
- VERSION = "0.1.6"
+ VERSION = "0.1.7"
end
View
2 spec/fixtures/config.yml
@@ -1,5 +1,5 @@
rabbit_jobs:
- host: example.com
+ url: amqp://example.com/vhost
exchange: 'my_exchange'
exchange_params:
durable: true
View
11 spec/unit/configuration_spec.rb
@@ -6,7 +6,7 @@
RabbitJobs.configure do |c|
c.disable_error_log
- c.host "somehost.lan"
+ c.url "amqp://somehost.lan"
c.exchange 'my_exchange', durable: true, auto_delete: false
@@ -16,7 +16,7 @@
RabbitJobs.config.to_hash.should == {
error_log: false,
- host: "somehost.lan",
+ url: "amqp://somehost.lan",
exchange: "my_exchange",
exchange_params: {
durable: true,
@@ -42,7 +42,7 @@
RabbitJobs.config.load_file(File.expand_path('../../fixtures/config.yml', __FILE__))
RabbitJobs.config.to_hash.should == {
- host: "example.com",
+ url: "amqp://example.com/vhost",
exchange: "my_exchange",
exchange_params: {
durable: true,
@@ -67,7 +67,7 @@
it 'use default config' do
RabbitJobs.config.to_hash.should == {
error_log: true,
- host: "localhost",
+ url: "amqp://localhost",
exchange: "rabbit_jobs",
exchange_params: {
auto_delete: false,
@@ -85,8 +85,7 @@
it 'returns settings on some methods' do
RabbitJobs.config.error_log == true
- RabbitJobs.config.host.should == 'localhost'
- RabbitJobs.config[:host].should == 'localhost'
+ RabbitJobs.config.url.should == 'amqp://localhost'
RabbitJobs.config.routing_keys.should == ['default']
RabbitJobs.config.exchange.should == 'rabbit_jobs'
RabbitJobs.config.queue_name('default').should == 'rabbit_jobs#default'

No commit comments for this range

Something went wrong with that request. Please try again.