Skip to content

Commit

Permalink
add register_dois_by_query rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 16, 2020
1 parent 9e79b37 commit 1e86cad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/jobs/handle_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HandleJob < ApplicationJob

# discard_on ActiveJob::DeserializationError

def perform(doi_id)
def perform(doi_id, _options = {})
doi = Doi.where(doi: doi_id).first

if doi.present?
Expand Down
2 changes: 1 addition & 1 deletion app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,7 @@ def self.loop_through_dois(options = {})
response = Doi.query(query, filter.merge(page: { size: size, cursor: cursor }))
break unless response.results.results.length.positive?

Rails.logger.info "#{label} #{response.results.results.length} Dois starting with _id #{response.results.to_a.first[:_id]}."
Rails.logger.info "#{label} #{response.results.results.length} Dois starting with _id #{response.results.to_a.first[:_id]}."
cursor = response.results.to_a.last[:sort]
Rails.logger.info "#{label} Cursor: #{cursor} "

Expand Down
17 changes: 17 additions & 0 deletions lib/tasks/doi.rake
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ namespace :doi do
puts Doi.loop_through_dois(options)
end

desc "Trigger DOI handle registration based on query"
task register_dois_by_query: :environment do
# Ensure we have specified a query of some kind.
if ENV["QUERY"].blank?
puts "ENV['QUERY'] is required"
exit
end

options = {
query: ENV["QUERY"],
label: "[RegisterDoiByQuery]",
job_name: "HandleJob",
cursor: ENV["CURSOR"].present? ? Base64.urlsafe_decode64(ENV["CURSOR"]).split(",", 2) : [],
}
puts Doi.loop_through_dois(options)
end

# until all Crossref DOIs are indexed as otherDoi
desc "Refresh metadata"
task refresh: :environment do
Expand Down

0 comments on commit 1e86cad

Please sign in to comment.