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

Stop the dispatching of new messages when a SIGTERM signal has been received #750

Merged
merged 4 commits into from
Oct 26, 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
7 changes: 5 additions & 2 deletions lib/shoryuken/extensions/active_job_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ def message(queue, job)
}

if queue.fifo?
# See https://github.com/phstc/shoryuken/issues/457
msg[:message_deduplication_id] = Digest::SHA256.hexdigest(JSON.dump(body.except('job_id')))
# See https://github.com/ruby-shoryuken/shoryuken/issues/457 and
# https://github.com/ruby-shoryuken/shoryuken/pull/750#issuecomment-1781317929
msg[:message_deduplication_id] = Digest::SHA256.hexdigest(
JSON.dump(body.except('job_id', 'enqueued_at'))
)
end

msg.merge(job_params.except(:message_attributes))
Expand Down
3 changes: 3 additions & 0 deletions lib/shoryuken/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def start
def stop!
initiate_stop

# Don't await here so the timeout below is not delayed
stop_new_dispatching

executor.shutdown
executor.kill unless executor.wait_for_termination(Shoryuken.options[:timeout])

Expand Down
6 changes: 4 additions & 2 deletions spec/shared_examples_for_active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ class TestJob < ActiveJob::Base; end
context 'when fifo' do
let(:fifo) { true }

it 'does not include job_id in the deduplication_id' do
it 'does not include job_id and enqueued_at in the deduplication_id' do
expect(queue).to receive(:send_message) do |hash|
message_deduplication_id = Digest::SHA256.hexdigest(JSON.dump(job.serialize.except('job_id')))
message_deduplication_id = Digest::SHA256.hexdigest(
JSON.dump(job.serialize.except('job_id', 'enqueued_at'))
)

expect(hash[:message_deduplication_id]).to eq(message_deduplication_id)
end
Expand Down
26 changes: 20 additions & 6 deletions spec/shoryuken/launcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,17 @@
end

it 'fires quiet, shutdown and stopped event' do
expect(subject).to receive(:fire_event).with(:quiet, true)
expect(subject).to receive(:fire_event).with(:shutdown, true)
expect(subject).to receive(:fire_event).with(:stopped)
allow(subject).to receive(:fire_event)
subject.stop
expect(subject).to have_received(:fire_event).with(:quiet, true)
expect(subject).to have_received(:fire_event).with(:shutdown, true)
expect(subject).to have_received(:fire_event).with(:stopped)
end

it 'stops the managers' do
subject.stop
expect(first_group_manager).to have_received(:stop_new_dispatching)
expect(second_group_manager).to have_received(:stop_new_dispatching)
end
end

Expand All @@ -83,9 +90,16 @@
end

it 'fires shutdown and stopped event' do
expect(subject).to receive(:fire_event).with(:shutdown, true)
expect(subject).to receive(:fire_event).with(:stopped)
allow(subject).to receive(:fire_event)
subject.stop!
expect(subject).to have_received(:fire_event).with(:shutdown, true)
expect(subject).to have_received(:fire_event).with(:stopped)
end

it 'stops the managers' do
subject.stop!
expect(first_group_manager).to have_received(:stop_new_dispatching)
expect(second_group_manager).to have_received(:stop_new_dispatching)
end
end
end
end
Loading