queue_map 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,7 +18,6 @@ if consumer_path.nil?
18
18
  end
19
19
 
20
20
  require "rubygems"
21
- require "background_process"
22
21
  require File.dirname(__FILE__) + "/../lib/queue_map"
23
22
  require File.dirname(__FILE__) + "/../lib/queue_map/consumer"
24
23
 
@@ -1,7 +1,7 @@
1
1
  class QueueMap::Consumer
2
2
  attr_accessor :count_workers, :worker_proc, :on_exception_proc
3
3
  attr_reader :name, :master_pid
4
- attr_writer :pid_file
4
+ attr_writer :pid_file, :log_file
5
5
  class Configurator
6
6
  def initialize(base)
7
7
  @base = base
@@ -14,6 +14,15 @@ class QueueMap::Consumer
14
14
  def on_exception(&block); @base.on_exception_proc = block; end
15
15
  def count_workers(value); @base.count_workers = value; end
16
16
  def pid_file(value); @base.pid_file = value; end
17
+ def log_file(value); @base.log_file = value; end
18
+
19
+ def respond_to?(*args)
20
+ super || @base.respond_to?(*args)
21
+ end
22
+
23
+ def method_missing(method_name, *args)
24
+ @base.send(method_name, *args)
25
+ end
17
26
  end
18
27
 
19
28
 
@@ -57,7 +66,15 @@ class QueueMap::Consumer
57
66
  end
58
67
 
59
68
  def pid_file
60
- "#{name}_consumer.pid"
69
+ @pid_file ||= "#{name}_consumer.pid"
70
+ end
71
+
72
+ def log_file
73
+ @log_file ||= "#{name}_consumer.log"
74
+ end
75
+
76
+ def logger
77
+ @logger ||= Logger.new(log_file)
61
78
  end
62
79
 
63
80
  def start
@@ -84,8 +101,8 @@ class QueueMap::Consumer
84
101
  if on_exception_proc
85
102
  on_exception_proc.call(e)
86
103
  else
87
- puts e
88
- puts e.backtrace
104
+ logger.error e.message
105
+ logger.error e.backtrace
89
106
  end
90
107
  end
91
108
  end
@@ -100,7 +117,7 @@ class QueueMap::Consumer
100
117
  begin
101
118
  run_consumer
102
119
  rescue Exception => e
103
- puts %(#{e}\n#{e.backtrace.join("\n")})
120
+ logger.error %(#{e}\n#{e.backtrace.join("\n")})
104
121
  end
105
122
  end)
106
123
  end
@@ -136,6 +153,7 @@ class QueueMap::Consumer
136
153
  Signal.trap("TERM") { stop(false) }
137
154
  Signal.trap("INT") { stop }
138
155
  after_fork_procs.each { |p| p.call }
156
+ logger.info "#{Process.pid}: running"
139
157
  run_consumer
140
158
  end
141
159
 
@@ -145,11 +163,11 @@ class QueueMap::Consumer
145
163
  begin
146
164
  Process.kill(graceful ? "INT" : "TERM", pid)
147
165
  rescue Errno::ESRCH => e
148
- puts "Unable to signal process #{pid}. Does the process not exist?"
166
+ logger.error "Unable to signal process #{pid}. Does the process not exist?"
149
167
  end
150
168
  end
151
169
 
152
- puts "#{Process.pid}: stopping (graceful: #{graceful})"
170
+ logger.info "#{Process.pid}: stopping (graceful: #{graceful})"
153
171
  if graceful
154
172
  @shutting_down = true
155
173
  else
@@ -1,3 +1,3 @@
1
1
  module QueueMap
2
- VERSION="0.2"
2
+ VERSION="0.3"
3
3
  end
data/lib/queue_map.rb CHANGED
@@ -6,9 +6,10 @@ module QueueMap
6
6
  autoload :Consumer, File.dirname(__FILE__) + "/queue_map/consumer"
7
7
  BUNNY_MUTEX = Mutex.new
8
8
  extend self
9
- attr_accessor :mode
9
+ attr_accessor :mode, :consumer_path
10
10
  attr_writer :consumer_base_path
11
- attr_accessor :consumer_path
11
+ attr_accessor
12
+ attr_reader :connection_info
12
13
 
13
14
  DEFAULT_ON_TIMEOUT = lambda { |r| nil }
14
15
 
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: queue_map
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- version: "0.2"
8
+ - 3
9
+ version: "0.3"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tim Harper