Skip to content

Commit ee8d212

Browse files
committed
Merge pull request resque#623 from dylanahsmith/child-signal-termination
Notify failure backend of processes killed by signals.
2 parents 47b7f6f + ac7f29a commit ee8d212

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/resque/worker.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,13 @@ def work(interval = 5.0, &block)
142142
rescue SystemCallError
143143
nil
144144
end
145+
job.fail(DirtyExit.new($?.to_s)) if $?.signaled?
145146
else
146147
unregister_signal_handlers if will_fork?
147148
procline "Processing #{job.queue} since #{Time.now.to_i}"
148149
reconnect
149150
perform(job, &block)
150-
exit! if will_fork?
151+
exit!(true) if will_fork?
151152
end
152153

153154
done_working

test/worker_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,5 +689,28 @@ def self.perform( run_time, rescue_time=nil )
689689
end
690690
end
691691
end
692+
693+
class SuicidalJob
694+
@queue = :jobs
695+
696+
def self.perform
697+
Process.kill('KILL', Process.pid)
698+
end
699+
700+
def self.on_failure_store_exception(exc, *args)
701+
@@failure_exception = exc
702+
end
703+
end
704+
705+
it "will notify failure hooks when a job is killed by a signal" do
706+
begin
707+
$TESTING = false
708+
Resque.enqueue(SuicidalJob)
709+
@worker.work(0)
710+
assert_equal Resque::DirtyExit, SuicidalJob.send(:class_variable_get, :@@failure_exception).class
711+
ensure
712+
$TESTING = true
713+
end
714+
end
692715
end
693716
end

0 commit comments

Comments
 (0)