Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that delayed_job workers handle SIGQUIT #3183

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/delayed_job/quit_trap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Class 'Worker' in the 'delayed_job' gem only handles SIGTERM & SIGINT which result in a graceful shutdown
# This monkey patch extends `start()` to also handle SIGQUIT.
# Could be replaced by https://github.com/collectiveidea/delayed_job/pull/900

module QuitTrap
def start
trap('QUIT') do
Thread.new { say 'Exiting...' }
stop
end

super
end
end

module Delayed
class Worker
prepend QuitTrap
end
end
2 changes: 2 additions & 0 deletions lib/tasks/jobs.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'delayed_job/quit_trap'

namespace :jobs do
desc 'Clear the delayed_job queue.'
task :clear do
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/lib/delayed_job/delayed_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
RSpec.describe 'delayed_job' do
describe 'version' do
it 'should not be updated' do
expect(Gem.loaded_specs['delayed_job'].version).to eq('4.1.9'), 'revisit monkey patch in lib/delayed_job/quit_trap.rb'
end
end
end