Skip to content

Commit

Permalink
Merge pull request #1457 from Sinjo/avoid-thread-kill
Browse files Browse the repository at this point in the history
Use flag to stop heartbeat thread rather than Thread.kill
  • Loading branch information
Chris C Cerami committed May 26, 2016
2 parents 7c9848a + 23da4e2 commit 32115d2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/resque/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,15 @@ def heartbeat!(time = Time.now)

def start_heartbeat
heartbeat!

@stop_heartbeat_thread = false
@heart = Thread.new do
loop do
sleep(Resque.heartbeat_interval)
until @stop_heartbeat_thread do
Resque.heartbeat_interval.times do
sleep(1)
break if @stop_heartbeat_thread
end

heartbeat!
end
end
Expand Down Expand Up @@ -628,7 +634,7 @@ def run_hook(name, *args)
end

def kill_background_threads
@heart.kill if @heart
@stop_heartbeat_thread = true if @heart
end

# Unregisters ourself as a worker. Useful when shutting down.
Expand Down

0 comments on commit 32115d2

Please sign in to comment.