Skip to content

Commit

Permalink
Sidekiq callback instead of internals for graceful shutdown
Browse files Browse the repository at this point in the history
Happens at the same time as the old code: https://github.com/sidekiq/sidekiq/blob/73c150d0430a8394cadb5cd49218895b113613a0/lib/sidekiq/launcher.rb#L47-L54 but this is less brittle.

Sidekiq::CLI is only defined when Sidekiq runs as a standalone process. Since 7.0 it can also run embedded in the web server process, and using this hook allows Iteration to be compatible with mode of operation. The same events are fired here: https://github.com/sidekiq/sidekiq/blob/73c150d0430a8394cadb5cd49218895b113613a0/lib/sidekiq/embedded.rb#L24-L30
  • Loading branch information
bdewater committed Jan 16, 2024
1 parent f3a89f8 commit 2776ef8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/job-iteration/integrations/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@

module JobIteration
module Integrations # @private
JobIteration.interruption_adapter = -> do
if defined?(Sidekiq::CLI) && Sidekiq::CLI.instance
Sidekiq::CLI.instance.launcher.stopping?
else
false
module Sidekiq
class << self
attr_accessor :stopping

def call
stopping
end
end
end

JobIteration.interruption_adapter = JobIteration::Integrations::Sidekiq

::Sidekiq.configure_server do |config|
config.on(:quiet) do
JobIteration::Integrations::Sidekiq.stopping = true
end
end
end
Expand Down

0 comments on commit 2776ef8

Please sign in to comment.