Skip to content

Commit f3ac4a0

Browse files
committed
print out deprecation notice about old signal handling
1 parent afa62c7 commit f3ac4a0

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/resque/worker.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def fork
248248

249249
# Runs all the methods needed when a worker begins its lifecycle.
250250
def startup
251+
warn "WARNING: This way of doing signal handling is now deprecated. Please see http://hone.heroku.com/resque/2012/08/21/resque-signals.html for more info." unless term_child
251252
enable_gc_optimizations
252253
register_signal_handlers
253254
prune_dead_workers

test/test_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,15 @@ def now
160160

161161
self.fake_time = nil
162162
end
163+
164+
def capture_stderr
165+
# The output stream must be an IO-like object. In this case we capture it in
166+
# an in-memory IO object so we can return the string value. You can assign any
167+
# IO object here.
168+
previous_stderr, $stderr = $stderr, StringIO.new
169+
yield
170+
$stderr.string
171+
ensure
172+
# Restore the previous value of stderr (typically equal to STDERR).
173+
$stderr = previous_stderr
174+
end

test/worker_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,5 +571,18 @@ def self.perform( run_time, rescue_time=nil )
571571
end
572572
end
573573
end
574+
575+
test "displays warning when not using term_child" do
576+
stderr = capture_stderr { @worker.work(0) }
577+
578+
assert stderr.match(/^WARNING:/)
579+
end
580+
581+
test "it does not display warning when using term_child" do
582+
@worker.term_child = "1"
583+
stderr = capture_stderr { @worker.work(0) }
584+
585+
assert !stderr.match(/^WARNING:/)
586+
end
574587
end
575588
end

0 commit comments

Comments
 (0)