From 1e86cad9d28675df4fc3077e0f9e9ae4b2adf5e4 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Wed, 16 Dec 2020 14:44:16 +0100 Subject: [PATCH] add register_dois_by_query rake task --- app/jobs/handle_job.rb | 2 +- app/models/doi.rb | 2 +- lib/tasks/doi.rake | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/jobs/handle_job.rb b/app/jobs/handle_job.rb index a92f091ac..98bf83ce1 100644 --- a/app/jobs/handle_job.rb +++ b/app/jobs/handle_job.rb @@ -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? diff --git a/app/models/doi.rb b/app/models/doi.rb index 8c85ba105..6e191fcef 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -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} " diff --git a/lib/tasks/doi.rake b/lib/tasks/doi.rake index 8bb794943..c1f73220c 100644 --- a/lib/tasks/doi.rake +++ b/lib/tasks/doi.rake @@ -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