Skip to content

Commit

Permalink
fire stopped event after executor is stopped (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan authored Sep 5, 2023
1 parent 3099c57 commit 5eb3309
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/shoryuken/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ def stop!
initiate_stop

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

return if executor.wait_for_termination(Shoryuken.options[:timeout])

executor.kill
fire_event(:stopped)
end

def stop
Expand All @@ -33,6 +32,8 @@ def stop

executor.shutdown
executor.wait_for_termination

fire_event(:stopped)
end

def healthy?
Expand Down
5 changes: 3 additions & 2 deletions lib/shoryuken/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Options
dispatch: [],
utilization_update: [],
quiet: [],
shutdown: []
shutdown: [],
stopped: []
}
}.freeze

Expand Down Expand Up @@ -134,7 +135,7 @@ def on_stop(&block)
end

# Register a block to run at a point in the Shoryuken lifecycle.
# :startup, :quiet or :shutdown are valid events.
# :startup, :quiet, :shutdown or :stopped are valid events.
#
# Shoryuken.configure_server do |config|
# config.on(:shutdown) do
Expand Down
31 changes: 31 additions & 0 deletions spec/shoryuken/launcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,35 @@
end
end
end

describe '#stop' do
before do
allow(first_group_manager).to receive(:stop_new_dispatching)
allow(first_group_manager).to receive(:await_dispatching_in_progress)
allow(second_group_manager).to receive(:stop_new_dispatching)
allow(second_group_manager).to receive(:await_dispatching_in_progress)
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)
subject.stop
end
end

describe '#stop!' do
before do
allow(first_group_manager).to receive(:stop_new_dispatching)
allow(first_group_manager).to receive(:await_dispatching_in_progress)
allow(second_group_manager).to receive(:stop_new_dispatching)
allow(second_group_manager).to receive(:await_dispatching_in_progress)
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)
subject.stop!
end
end
end

0 comments on commit 5eb3309

Please sign in to comment.