Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add interruption adapter for GoodJob #464

Merged
merged 1 commit into from
Sep 23, 2024
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
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
Loading