resqued 0.7.2 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4dd030c6805cad2c45c30a29e5415913b813b6b9
4
- data.tar.gz: 997391384ab8db66c4dc1b9fc61efd3b2e9ce556
3
+ metadata.gz: 2d5c9debc1401bd8eba5b54ea6d6c2f9ad9787ac
4
+ data.tar.gz: 2dc545b30cdc8a84c5d1264e4ba68126d087d232
5
5
  SHA512:
6
- metadata.gz: d1d646630aeceb8d1b4915e23d3f5dae31cf06d7aa7bdeca11efa7f5c632345c3e3c42668a49cc204b1a4e1a63df011ec6d399c04f6f26c78281b8818e82826d
7
- data.tar.gz: 7c774e66d83c5a8dd5279c2b0c57ce83bdd7cf12f565a48c3d1c50a65b148da0297025606b92443126901cec54ec648ef06635781eba4c5d2e0c97815745968a
6
+ metadata.gz: 91b94be95c8bc28778f105505e075b56f5f70587a6b51efda99551e8b3503000354d31cc6fa16b10538653c39946a3a51d5c38e336a79dfd87afe9814f18fe31
7
+ data.tar.gz: 659f8eca03013d49bcaef2641e8dcc7f56d6018b814924f01e5eef362dae9e5d4b05d971adf307739b3b810cf12fb9853e389ee8a08f4775d7dfa2cc4dcbc25f
@@ -57,6 +57,7 @@ module Resqued
57
57
  end
58
58
 
59
59
  SIGNALS = [ :CONT, :QUIT, :INT, :TERM ]
60
+ ALL_SIGNALS = SIGNALS + [ :CHLD ]
60
61
 
61
62
  SIGNAL_QUEUE = []
62
63
 
@@ -68,6 +69,7 @@ module Resqued
68
69
  write_procline('starting')
69
70
 
70
71
  config = Resqued::Config.new(@config_paths)
72
+ set_default_resque_logger
71
73
  config.before_fork
72
74
  report_to_master("RUNNING")
73
75
 
@@ -79,6 +81,14 @@ module Resqued
79
81
  burn_down_workers(exit_signal || :QUIT)
80
82
  end
81
83
 
84
+ # Private.
85
+ def set_default_resque_logger
86
+ require 'resque'
87
+ if Resque.respond_to?('logger=')
88
+ Resque.logger = Resqued::Logging.build_logger
89
+ end
90
+ end
91
+
82
92
  # Private.
83
93
  def run_workers_run
84
94
  loop do
@@ -102,6 +112,7 @@ module Resqued
102
112
  def burn_down_workers(signal)
103
113
  loop do
104
114
  check_for_expired_workers
115
+ write_procline('shutdown')
105
116
  SIGNAL_QUEUE.clear
106
117
 
107
118
  break if :no_child == reap_workers(Process::WNOHANG)
@@ -217,6 +228,7 @@ module Resqued
217
228
  procline = "#{procline_version} listener"
218
229
  procline << " #{@listener_id}" if @listener_id
219
230
  procline << " [#{status}]"
231
+ procline << " [#{running_workers.size} workers]" if status == 'shutdown'
220
232
  procline << " #{@config_paths.join(' ')}"
221
233
  $0 = procline
222
234
  end
@@ -1,9 +1,39 @@
1
+ require 'mono_logger'
2
+
1
3
  module Resqued
2
4
  # Mixin for any class that wants to write messages to the log file.
3
5
  module Logging
4
6
  # Global logging state.
5
7
  class << self
6
- # Public: Get an IO to write log messages to.
8
+ # Public: Get a `Logger`.
9
+ def logger
10
+ @logger ||= build_logger
11
+ end
12
+
13
+ def build_logger
14
+ MonoLogger.new(ResquedLoggingIOWrapper.new).tap do |logger|
15
+ logger.formatter = ResquedLogFormatter.new
16
+ end
17
+ end
18
+
19
+ class ResquedLogFormatter < ::Logger::Formatter
20
+ def call(severity, time, progname, msg)
21
+ "[%s#%6d] %5s %s -- %s\n" % [format_datetime(time), $$, severity, progname, msg2str(msg)]
22
+ end
23
+ end
24
+
25
+ # Private: Lets our logger reopen its logfile without monologger EVEN KNOWING.
26
+ class ResquedLoggingIOWrapper
27
+ def method_missing(*args)
28
+ ::Resqued::Logging.logging_io.send(*args)
29
+ end
30
+
31
+ def respond_to?(*args)
32
+ ::Resqued::Logging.logging_io.respond_to?(*args)
33
+ end
34
+ end
35
+
36
+ # Private: Get an IO to write log messages to.
7
37
  def logging_io
8
38
  @logging_io = nil if @logging_io && @logging_io.closed?
9
39
  @logging_io ||=
@@ -51,8 +81,9 @@ module Resqued
51
81
  end
52
82
 
53
83
  # Private (in classes that include this module)
54
- def log(message)
55
- Resqued::Logging.logging_io.puts "[#{$$} #{Time.now.strftime('%H:%M:%S')}] #{message}"
84
+ def log(level, message = nil)
85
+ level, message = :info, level if message.nil?
86
+ Resqued::Logging.logger.send(level, self.class.name) { message }
56
87
  end
57
88
  end
58
89
  end
@@ -1,3 +1,3 @@
1
1
  module Resqued
2
- VERSION = '0.7.2'
2
+ VERSION = '0.7.4'
3
3
  end
@@ -57,25 +57,13 @@ module Resqued
57
57
  @killed = false
58
58
  if @pid = fork
59
59
  # still in the listener
60
+ log "Forked worker #{@pid}"
60
61
  else
61
62
  # In case we get a signal before resque is ready for it.
62
- [:QUIT, :TERM, :INT].each { |signal| trap(signal) { exit 1 } }
63
+ Resqued::Listener::ALL_SIGNALS.each { |signal| trap(signal, 'DEFAULT') }
64
+ trap(:QUIT) { exit! 0 } # If we get a QUIT during boot, just spin back down.
63
65
  $0 = "STARTING RESQUE FOR #{queues.join(',')}"
64
- if Resque.respond_to?("logger")
65
- Resque.logger.level = Logger::INFO
66
- Resque.logger.formatter = Resque::VerboseFormatter.new
67
- end
68
- if ! log_to_stdout?
69
- lf = Resqued::Logging.logging_io
70
- if Resque.respond_to?("logger=")
71
- Resque.logger = Resque.logger.class.new(lf)
72
- else
73
- $stdout.reopen(lf)
74
- lf.close
75
- end
76
- end
77
66
  resque_worker = Resque::Worker.new(*queues)
78
- resque_worker.log "Starting worker #{resque_worker}"
79
67
  resque_worker.term_child = true if resque_worker.respond_to?('term_child=')
80
68
  Resque.redis.client.reconnect
81
69
  @config.after_fork(resque_worker)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resqued
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Burke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2013-11-13 00:00:00.000000000 Z
11
+ date: 2013-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kgio
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: mono_logger
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: debugger
43
57
  requirement: !ruby/object:Gem::Requirement