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 Jun 3, 2024
1 parent 10787b9 commit 3b95734
Show file tree
Hide file tree
Showing 3 changed files with 33 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
30 changes: 30 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,30 @@
# frozen_string_literal: true

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

begin
# GoodJob.current_thread_shutting_down? was introduced in GoodJob 3.26
gem("good_job", ">= 3.26")
rescue Gem::LoadError
warn("job-iteration's interruption adapter for GoodJob requires GoodJob 3.26 or newer")
return
end

module JobIteration
module InterruptionAdapters
module GoodJobAdapter
class << self
def call
!!::GoodJob.current_thread_shutting_down?
end
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 3b95734

Please sign in to comment.