Skip to content

Commit

Permalink
Merge pull request #523 from kakubin/interruption_adapter_aws_activej…
Browse files Browse the repository at this point in the history
…ob_sqs

Add interruption adapter for aws-activejob-sqs
  • Loading branch information
Mangara authored Dec 9, 2024
2 parents 90e0667 + 5c34c75 commit 92cbe76
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [340](https://github.com/Shopify/job-iteration/pull/340) Add `cursor.iteration` instrumentation for the query to fetch the next batch of records for the Active Record cursor.
- [513](https://github.com/Shopify/job-iteration/pull/513) Deprecate returning enumerators from `build_enumerator` that are not wrapped with `enumerator_builder.wrap`. The built-in enumerator builders now always wrap.
- [523](https://github.com/Shopify/job-iteration/pull/523) Add interruption adapter for [aws-activejob-sqs](https://github.com/aws/aws-activejob-sqs-ruby).

## v1.7.0 (Oct 11, 2024)

Expand Down
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 = [:good_job, :resque, :sidekiq, :solid_queue].freeze # @api private
BUNDLED_ADAPTERS = [:good_job, :resque, :sidekiq, :solid_queue, :sqs].freeze # @api private

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

begin
require "aws-activejob-sqs"
rescue LoadError
# Aws::ActiveJob::SQS is not available, no need to load the adapter
return
end

begin
# Aws::ActiveJob::SQS.on_worker_stop was introduced in Aws::ActiveJob::SQS 0.1.1
gem("aws-activejob-sqs", ">= 0.1.1")
rescue Gem::LoadError
warn("job-iteration's interruption adapter for SQS requires aws-activejob-sqs 0.1.1 or newer")
return
end

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

def call
stopping
end
end

Aws::ActiveJob::SQS.on_worker_stop do
SqsAdapter.stopping = true
end
end

register(:sqs, SqsAdapter)
end
end
2 changes: 1 addition & 1 deletion test/integration/interruption_adapters_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class InterruptionAdaptersTest < ActiveSupport::TestCase
require 'bundler/setup'
require 'job-iteration'
adapters_to_exclude = [:good_job, :solid_queue] # These require a Rails app to be loaded
adapters_to_exclude = [:good_job, :solid_queue, :sqs] # These require a Rails app to be loaded
adapters_to_test = JobIteration::InterruptionAdapters::BUNDLED_ADAPTERS - adapters_to_exclude
adapters_to_test.each do |name|
Expand Down

0 comments on commit 92cbe76

Please sign in to comment.