rabbit_jobs 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ require 'rabbit_jobs'
4
4
  require 'json'
5
5
 
6
6
  RabbitJobs.configure do |c|
7
- c.host "127.0.0.1"
7
+ c.url "amqp://localhost"
8
8
 
9
9
  c.exchange 'test_exchange', durable: true, auto_delete: false
10
10
 
@@ -15,7 +15,7 @@ module RabbitJobs
15
15
  block.call(connection, exchange)
16
16
 
17
17
  else
18
- AMQP.start(host: RJ.config.host) do |connection|
18
+ AMQP.start(RJ.config.url) do |connection|
19
19
 
20
20
  channel = AMQP::Channel.new(connection)
21
21
 
@@ -15,11 +15,22 @@ module RabbitJobs
15
15
  end
16
16
 
17
17
  def load_config
18
- self.configure do |c|
19
- c.host 'localhost'
20
- c.exchange 'rabbit_jobs', auto_delete: false, durable: true
21
- c.queue 'default', auto_delete: false, ack: true, durable: true
18
+ if defined?(Rails) && Rails.respond_to?(:root)
19
+ config_file = Rails.root.join('config/rabbit_jobs.yml')
20
+ if File.exists?(config_file)
21
+ @@configuration ||= Configuration.new
22
+ @@configuration.load_file(config_file)
23
+ end
24
+ end
25
+
26
+ unless @@configuration
27
+ self.configure do |c|
28
+ c.url 'amqp://localhost'
29
+ c.exchange 'rabbit_jobs', auto_delete: false, durable: true
30
+ c.queue 'default', auto_delete: false, ack: true, durable: true
31
+ end
22
32
  end
33
+
23
34
  @@configuration
24
35
  end
25
36
 
@@ -50,7 +61,7 @@ module RabbitJobs
50
61
  def initialize
51
62
  @data = {
52
63
  error_log: true,
53
- host: 'localhost',
64
+ url: 'amqp://localhost',
54
65
  exchange: 'rabbit_jobs',
55
66
  exchange_params: DEFAULT_EXCHANGE_PARAMS,
56
67
  queues: {}
@@ -70,8 +81,12 @@ module RabbitJobs
70
81
  end
71
82
  end
72
83
 
73
- def mail_errors_from
74
- @data[:mail_errors_form]
84
+ def mail_errors_from(email = nil)
85
+ if email
86
+ @data[:mail_errors_from] = email
87
+ else
88
+ @data[:mail_errors_from]
89
+ end
75
90
  end
76
91
 
77
92
  def error_log
@@ -82,12 +97,12 @@ module RabbitJobs
82
97
  @data[:error_log] = false
83
98
  end
84
99
 
85
- def host(value = nil)
100
+ def url(value = nil)
86
101
  if value
87
102
  raise ArgumentError unless value.is_a?(String) && value != ""
88
- @data[:host] = value.to_s
103
+ @data[:url] = value.to_s
89
104
  else
90
- @data[:host]
105
+ @data[:url]
91
106
  end
92
107
  end
93
108
 
@@ -133,9 +148,13 @@ module RabbitJobs
133
148
  def convert_yaml_config(yaml)
134
149
  if yaml['rabbit_jobs']
135
150
  convert_yaml_config(yaml['rabbit_jobs'])
151
+ elsif defined?(Rails) && yaml[Rails.env.to_s]
152
+ convert_yaml_config(yaml[Rails.env.to_s])
136
153
  else
137
- @data = {host: nil, exchange: nil, queues: {}}
138
- host yaml['host']
154
+ @data = {url: nil, exchange: nil, queues: {}}
155
+ %w(url exchange mail_errors_to mail_errors_from).each do |m|
156
+ self.send(m, yaml[m])
157
+ end
139
158
  exchange yaml['exchange'], symbolize_keys!(yaml['exchange_params'])
140
159
  yaml['queues'].each do |name, params|
141
160
  queue name, symbolize_keys!(params) || {}
@@ -59,7 +59,7 @@ module RabbitJobs
59
59
  def self.with_bunny(&block)
60
60
  raise ArgumentError unless block
61
61
 
62
- Bunny.run(host: RJ.config.host, logging: false) do |bunny|
62
+ Bunny.run(url: RJ.config.url, logging: false) do |bunny|
63
63
  block.call(bunny)
64
64
  end
65
65
  end
@@ -14,10 +14,8 @@ namespace :rj do
14
14
  daemon
15
15
  end
16
16
 
17
- task :setup
18
-
19
17
  desc "Start a Rabbit Jobs worker"
20
- task :worker => [ :preload, :setup ] do
18
+ task :worker => :environment do
21
19
  require 'rabbit_jobs'
22
20
 
23
21
  queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',')
@@ -27,14 +25,14 @@ namespace :rj do
27
25
  end
28
26
 
29
27
  desc "Start a Rabbit Jobs scheduler"
30
- task :scheduler => [ :preload, :setup ] do
28
+ task :scheduler => :environment do
31
29
  scheduler = initialize_rj_daemon(RabbitJobs::Scheduler.new)
32
30
 
33
31
  scheduler.work
34
32
  end
35
33
 
36
34
  # Preload app files if this is Rails
37
- task :preload => :setup do
35
+ task :environment do
38
36
  if defined?(Rails) && Rails.respond_to?(:application)
39
37
  # Rails 3
40
38
  # Rails.application.eager_load!
@@ -1,3 +1,3 @@
1
1
  module RabbitJobs
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  rabbit_jobs:
2
- host: example.com
2
+ url: amqp://example.com/vhost
3
3
  exchange: 'my_exchange'
4
4
  exchange_params:
5
5
  durable: true
@@ -6,7 +6,7 @@ describe RabbitJobs::Configuration do
6
6
  RabbitJobs.configure do |c|
7
7
  c.disable_error_log
8
8
 
9
- c.host "somehost.lan"
9
+ c.url "amqp://somehost.lan"
10
10
 
11
11
  c.exchange 'my_exchange', durable: true, auto_delete: false
12
12
 
@@ -16,7 +16,7 @@ describe RabbitJobs::Configuration do
16
16
 
17
17
  RabbitJobs.config.to_hash.should == {
18
18
  error_log: false,
19
- host: "somehost.lan",
19
+ url: "amqp://somehost.lan",
20
20
  exchange: "my_exchange",
21
21
  exchange_params: {
22
22
  durable: true,
@@ -42,7 +42,7 @@ describe RabbitJobs::Configuration do
42
42
  RabbitJobs.config.load_file(File.expand_path('../../fixtures/config.yml', __FILE__))
43
43
 
44
44
  RabbitJobs.config.to_hash.should == {
45
- host: "example.com",
45
+ url: "amqp://example.com/vhost",
46
46
  exchange: "my_exchange",
47
47
  exchange_params: {
48
48
  durable: true,
@@ -67,7 +67,7 @@ describe RabbitJobs::Configuration do
67
67
  it 'use default config' do
68
68
  RabbitJobs.config.to_hash.should == {
69
69
  error_log: true,
70
- host: "localhost",
70
+ url: "amqp://localhost",
71
71
  exchange: "rabbit_jobs",
72
72
  exchange_params: {
73
73
  auto_delete: false,
@@ -85,8 +85,7 @@ describe RabbitJobs::Configuration do
85
85
 
86
86
  it 'returns settings on some methods' do
87
87
  RabbitJobs.config.error_log == true
88
- RabbitJobs.config.host.should == 'localhost'
89
- RabbitJobs.config[:host].should == 'localhost'
88
+ RabbitJobs.config.url.should == 'amqp://localhost'
90
89
  RabbitJobs.config.routing_keys.should == ['default']
91
90
  RabbitJobs.config.exchange.should == 'rabbit_jobs'
92
91
  RabbitJobs.config.queue_name('default').should == 'rabbit_jobs#default'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbit_jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-06 00:00:00.000000000 Z
12
+ date: 2012-05-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amqp
16
- requirement: &70176780311600 !ruby/object:Gem::Requirement
16
+ requirement: &70239702675840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.9'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70176780311600
24
+ version_requirements: *70239702675840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bunny
27
- requirement: &70176780311100 !ruby/object:Gem::Requirement
27
+ requirement: &70239702675060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.7'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70176780311100
35
+ version_requirements: *70239702675060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70176780310720 !ruby/object:Gem::Requirement
38
+ requirement: &70239702674400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70176780310720
46
+ version_requirements: *70239702674400
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rufus-scheduler
49
- requirement: &70176780310180 !ruby/object:Gem::Requirement
49
+ requirement: &70239702661400 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '2.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70176780310180
57
+ version_requirements: *70239702661400
58
58
  description: Background jobs on RabbitMQ
59
59
  email:
60
60
  - lazureykis@gmail.com