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'
39 lines
668 B
Ruby
39 lines
668 B
Ruby
class SqsService
|
|
attr_reader :url
|
|
|
|
def initialize(url)
|
|
@url = url
|
|
end
|
|
|
|
def enabled?
|
|
Danbooru.config.aws_sqs_enabled? && credentials.set? && url.present?
|
|
end
|
|
|
|
def send_message(string, options = {})
|
|
return unless enabled?
|
|
|
|
sqs.send_message(
|
|
options.merge(
|
|
message_body: string,
|
|
queue_url: url
|
|
)
|
|
)
|
|
end
|
|
|
|
private
|
|
|
|
def credentials
|
|
@credentials ||= Aws::Credentials.new(
|
|
Danbooru.config.aws_access_key_id,
|
|
Danbooru.config.aws_secret_access_key
|
|
)
|
|
end
|
|
|
|
def sqs
|
|
@sqs ||= Aws::SQS::Client.new(
|
|
credentials: credentials,
|
|
region: Danbooru.config.aws_sqs_region
|
|
)
|
|
end
|
|
end
|