sqs_service.rb: fix exception when related tags sqs not configured.
Fixes this exception when Danbooru.config.aws_sqs_enabled? is true but
Danborou.config.aws_sqs_reltagcalc_url is not configured:
ArgumentError exception raised
missing required parameter params[:queue_url]
app/logical/sqs_service.rb:11:in `send_message'
app/models/tag.rb:674:in `update_related_if_outdated'
app/models/tag.rb:698:in `related_tag_array'
app/presenters/post_set_presenters/post.rb:49:in `related_tags_for_single'
app/presenters/post_set_presenters/post.rb:19:in `related_tags'
app/presenters/post_set_presenters/post.rb:8:in `initialize'
app/logical/post_sets/post.rb:181:in `new'
app/logical/post_sets/post.rb:181:in `presenter'
app/views/posts/index.html.erb:14:in `_app_views_posts_index_html_erb___3235672853362939702_47243208308540'
app/controllers/posts_controller.rb:16:in `index'
This commit is contained in:
@@ -5,8 +5,12 @@ class SqsService
|
|||||||
@url = url
|
@url = url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enabled?
|
||||||
|
Danbooru.config.aws_sqs_enabled? && credentials.set? && url.present?
|
||||||
|
end
|
||||||
|
|
||||||
def send_message(string, options = {})
|
def send_message(string, options = {})
|
||||||
return unless Danbooru.config.aws_sqs_enabled?
|
return unless enabled?
|
||||||
|
|
||||||
sqs.send_message(
|
sqs.send_message(
|
||||||
options.merge(
|
options.merge(
|
||||||
@@ -18,16 +22,17 @@ class SqsService
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def credentials
|
||||||
|
@credentials ||= Aws::Credentials.new(
|
||||||
|
Danbooru.config.aws_access_key_id,
|
||||||
|
Danbooru.config.aws_secret_access_key
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def sqs
|
def sqs
|
||||||
@sqs ||= begin
|
@sqs ||= Aws::SQS::Client.new(
|
||||||
credentials = Aws::Credentials.new(
|
credentials: credentials,
|
||||||
Danbooru.config.aws_access_key_id,
|
region: Danbooru.config.aws_sqs_region
|
||||||
Danbooru.config.aws_secret_access_key
|
)
|
||||||
)
|
|
||||||
Aws::SQS::Client.new(
|
|
||||||
credentials: credentials,
|
|
||||||
region: Danbooru.config.aws_sqs_region
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user