-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #464 from olivier-thatch/olivier/good-job-integration
Add interruption adapter for GoodJob
- Loading branch information
Showing
3 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
lib/job-iteration/interruption_adapters/good_job_adapter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters