Skip to content

Commit

Permalink
Fix setting item visibility timeout (#131)
Browse files Browse the repository at this point in the history
I am unsure why it happened now. Was it introduced in DispatchRider 2.0 or 2.1 ? 
Was it a change upstream in aws-sdk-sqs ?

* test using `ensure`, because item.visibility_timeout krash

* use change visibility

* make aws sns/sqs required runtime gem

* fix openstruct in specs

* use a proc

* require gems, do not rescue NameError exceptions

* bump version

* stub object for the method call instead

* rubocop
  • Loading branch information
mathieujobin authored Dec 9, 2022
1 parent 922d7f0 commit 7abe708
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dispatch-rider.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency 'activesupport', '>= 5.2.0'
gem.add_runtime_dependency 'activemodel', '>= 5.2.0'
gem.add_runtime_dependency 'activerecord', '>= 5.2.0'
gem.add_runtime_dependency 'aws-sdk-sqs', '~> 1.30'
gem.add_runtime_dependency 'aws-sdk-sns', '~> 1.30'
gem.add_runtime_dependency 'daemons', '~> 1.2'
gem.add_runtime_dependency 'retriable', '~> 3.1', '>= 3.1.2'
# appsignal is an optional runtime dependency,
# I am marking it as development for those that don't need it
gem.add_development_dependency 'appsignal', '~> 1.0'

gem.add_development_dependency 'aws-sdk-sqs', '~> 1.30'
gem.add_development_dependency 'aws-sdk-sns', '~> 1.30'
gem.add_development_dependency 'bundler', '< 3.0'
gem.add_development_dependency 'coveralls_reborn', '~> 0.25'
gem.add_development_dependency 'simplecov-lcov'
Expand Down
4 changes: 2 additions & 2 deletions lib/dispatch-rider/notification_services/aws_sns.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'aws-sdk-sns'

# This is a basic implementation of the Notification service using Amazon SNS.
# The expected usage is as follows :
# notification_service = DispatchRider::NotificationServices::AwsSns.new
Expand All @@ -9,8 +11,6 @@ module NotificationServices
class AwsSns < Base
def notifier_builder
Aws::SNS::Client
rescue NameError
raise AdapterNotFoundError.new(self.class.name, 'aws-sdk')
end

def channel_registrar_builder
Expand Down
4 changes: 2 additions & 2 deletions lib/dispatch-rider/queue_services/aws_sqs.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'aws-sdk-sqs'

# This queue service is based on aws sqs.
# To make this queue service work, one would need the aws sqs gem to be installed.
module DispatchRider
Expand All @@ -23,8 +25,6 @@ def assign_storage(attrs)
else
raise RecordInvalid.new(self, ["Either name or url have to be specified"])
end
rescue NameError
raise AdapterNotFoundError.new(self.class.name, 'aws-sdk')
end

def pop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def initialize(message, raw_item, queue, queue_visibility_timeout)
# NOTE: Setting the visibility timeout resets the timeout to NOW and makes it visibility timeout this time
# Essentially resetting the timer on this message
def extend_timeout(timeout)
item.visibility_timeout = timeout
item.change_visibility({
visibility_timeout: timeout # required
})
@total_timeout = timeout + (Time.now - start_time).to_i if timeout > 0
end

Expand Down
2 changes: 1 addition & 1 deletion lib/dispatch-rider/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# This file specifies the current version of the gem.
module DispatchRider
VERSION = '2.1.0'
VERSION = '2.2.0'
end
7 changes: 6 additions & 1 deletion spec/lib/dispatch-rider/queue_services/aws_sqs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
before do
allow_any_instance_of(Aws::SQS::Client).to receive(:list_queues).and_return(OpenStruct.new({queue_urls: ["the.queue.url"]}))
allow_any_instance_of(Aws::SQS::Client).to receive(:get_queue_attributes).and_return(
OpenStruct.new({attributes: {"VisibilityTimeout"=>visibility_timeout}})
OpenStruct.new(
{
attributes: {"VisibilityTimeout"=>visibility_timeout}
}
)
)
end

Expand Down Expand Up @@ -136,6 +140,7 @@
end

before do
allow(response_message).to receive(:change_visibility)
allow_any_instance_of(Aws::SQS::Queue).to receive(:receive_messages).and_return(OpenStruct.new({first: response_message }))
end

Expand Down

0 comments on commit 7abe708

Please sign in to comment.