rabbit_jobs 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,8 @@ module RabbitJobs
15
15
  end
16
16
 
17
17
  def load_config(config_file = nil)
18
+ @@configuration ||= nil
19
+
18
20
  config_file ||= defined?(Rails) && Rails.respond_to?(:root) && Rails.root.join('config/rabbit_jobs.yml')
19
21
  if config_file
20
22
  if File.exists?(config_file)
@@ -27,7 +29,6 @@ module RabbitJobs
27
29
  self.configure do |c|
28
30
  c.url 'amqp://localhost/'
29
31
  c.exchange 'rabbit_jobs', auto_delete: false, durable: true
30
- c.queue 'default', auto_delete: false, ack: true, durable: true
31
32
  end
32
33
  end
33
34
 
@@ -25,11 +25,8 @@ module RabbitJobs::Job
25
25
  else
26
26
  $0 = "##{@child_pid} #{self.class}.perform(#{ params.map(&:inspect).join(', ') }) #{$0}"
27
27
  begin
28
- if defined?(ActiveRecord::Base)
29
- ActiveRecord::Base.establish_connection
30
- end
31
- if defined?(MongoMapper)
32
- MongoMapper.database.connection.connect_to_master
28
+ RJ.__after_fork_callbacks.each do |callback|
29
+ callback.call()
33
30
  end
34
31
 
35
32
  self.class.perform(*params)
@@ -12,6 +12,7 @@ module RabbitJobs
12
12
  extend AmqpHelpers
13
13
 
14
14
  def publish(klass, *params)
15
+ RJ.config.queue('default', RJ::Configuration::DEFAULT_QUEUE_PARAMS) if RJ.config.routing_keys.empty?
15
16
  key = RJ.config.routing_keys.first
16
17
  publish_to(key, klass, *params)
17
18
  end
@@ -8,7 +8,7 @@ namespace :rj do
8
8
  def initialize_rj_daemon(daemon)
9
9
  daemon.pidfile = ENV['PIDFILE']
10
10
  daemon.background = %w(yes true).include? ENV['BACKGROUND']
11
- RJ.logger = ::Logger.new(ENV['LOGFILE']) if ENV['LOGFILE']
11
+ RJ.logger = ::Logger.new(ENV['LOGFILE'] || $stdout)
12
12
  RJ.logger.level = ENV['VERBOSE'] ? Logger::INFO : Logger::WARN
13
13
 
14
14
  daemon
@@ -1,3 +1,3 @@
1
1
  module RabbitJobs
2
- VERSION = "0.1.12"
2
+ VERSION = "0.1.13"
3
3
  end
@@ -108,13 +108,6 @@ module RabbitJobs
108
108
  else
109
109
  # daemonize child process
110
110
  Process.daemon(true)
111
-
112
- if defined?(ActiveRecord::Base)
113
- ActiveRecord::Base.establish_connection
114
- end
115
- if defined?(MongoMapper)
116
- MongoMapper.database.connection.connect_to_master
117
- end
118
111
  end
119
112
  end
120
113
 
data/lib/rabbit_jobs.rb CHANGED
@@ -30,6 +30,17 @@ module RabbitJobs
30
30
  def logger
31
31
  @logger ||= Logger.new $stdout
32
32
  end
33
+
34
+ def after_fork(&block)
35
+ raise ArgumentError.new("No block passed to after_fork") unless block_given?
36
+ @@after_fork_callbacks ||= []
37
+
38
+ @@after_fork_callbacks << block
39
+ end
40
+
41
+ def __after_fork_callbacks
42
+ @@after_fork_callbacks ||= []
43
+ end
33
44
  end
34
45
 
35
46
  RJ = RabbitJobs
@@ -11,6 +11,7 @@ describe RabbitJobs::Scheduler do
11
11
 
12
12
  scheduler.work(10) # work for 1 second
13
13
 
14
+ RJ.config.queue 'default', RJ::Configuration::DEFAULT_QUEUE_PARAMS
14
15
  puts "messages queued: " + RabbitJobs::Publisher.purge_queue('default').to_s
15
16
  RabbitJobs::Publisher.purge_queue('default').should == 0
16
17
  end
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.12
4
+ version: 0.1.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-28 00:00:00.000000000 Z
12
+ date: 2012-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amqp
@@ -129,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  segments:
131
131
  - 0
132
- hash: 2915034037780262995
132
+ hash: 1322251184713494268
133
133
  required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  none: false
135
135
  requirements:
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  segments:
140
140
  - 0
141
- hash: 2915034037780262995
141
+ hash: 1322251184713494268
142
142
  requirements: []
143
143
  rubyforge_project:
144
144
  rubygems_version: 1.8.24