Skip to content

Commit

Permalink
Add interruption adapter for GoodJob
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier-thatch committed Feb 22, 2024
1 parent a01977d commit df0492e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/job-iteration/interruption_adapters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module JobIteration
module InterruptionAdapters
BUNDLED_ADAPTERS = [:resque, :sidekiq].freeze # @api private
BUNDLED_ADAPTERS = [:good_job, :resque, :sidekiq].freeze # @api private

class << self
# Returns adapter for specified name.
Expand Down
28 changes: 28 additions & 0 deletions lib/job-iteration/interruption_adapters/good_job_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

begin
require "good_job"
rescue LoadError
# GoodJob is not available, no need to load the adapter
return
end

module JobIteration
module InterruptionAdapters
module GoodJobAdapter
class << self
attr_accessor :stopping

def call
stopping
end
end

ActiveSupport::Notifications.subscribe("scheduler_shutdown_start.good_job") do
GoodJobAdapter.stopping = true
end
end

register(:good_job, GoodJobAdapter)
end
end
3 changes: 2 additions & 1 deletion test/integration/interruption_adapters_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class InterruptionAdaptersTest < ActiveSupport::TestCase
ruby = <<~RUBY
require 'bundler/setup'
require 'job-iteration'
JobIteration::InterruptionAdapters::BUNDLED_ADAPTERS.each do |name|
# The adapter for GoodJob cannot be easily tested at the moment.
JobIteration::InterruptionAdapters::BUNDLED_ADAPTERS.excluding(:good_job).each do |name|
JobIteration::InterruptionAdapters.lookup(name)
end
RUBY
Expand Down

0 comments on commit df0492e

Please # to comment.