-
Notifications
You must be signed in to change notification settings - Fork 8
Refactor ReindexByDoiJob to include Shoryuken::Worker and update perform method #1495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,18 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # frozen_string_literal: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class ReindexByDoiJob < ApplicationJob | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| include Shoryuken::Worker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queue_as :lupo_background | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shoryuken_options queue: -> { "#{ENV["RAILS_ENV"]}_lupo_background" }, auto_delete: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def perform(sqs_message = nil, data = nil) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parsed = JSON.parse(data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return unless parsed.is_a?(Hash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doi_id = parsed["doi"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return if doi_id.blank? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle invalid payloads before parsing.
💡 Proposed fix def perform(sqs_message = nil, data = nil)
- parsed = JSON.parse(data)
+ parsed =
+ case data
+ when Hash
+ data
+ when String
+ JSON.parse(data)
+ else
+ return
+ end
return unless parsed.is_a?(Hash)
- doi_id = parsed["doi"]
+ doi_id = parsed["doi"] || parsed[:doi]
return if doi_id.blank?
doi = Doi.find_by(doi: doi_id)
return unless doi.present?
if doi.agency == "datacite"
DataciteDoiImportInBulkJob.perform_later([doi.id], index: DataciteDoi.active_index)
else
OtherDoiImportInBulkJob.perform_later([doi.id], index: OtherDoi.active_index)
end
+ rescue JSON::ParserError
+ return
end📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def perform(doi_id, _options = {}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doi = Doi.find_by(doi: doi_id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return unless doi.present? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the Shoryuken queue name aligned with the publisher.
Line 7 hard-codes
ENV["RAILS_ENV"], butapp/services/sqs_message_service.rb:6-7publishes toENV["SQS_PREFIX"].presence || Rails.env. In prefixed environments, producers will send to<prefix>_lupo_backgroundwhile this worker listens on<RAILS_ENV>_lupo_background, so it will never see those messages.💡 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents