Skip to content

Commit

Permalink
better handling of cursor env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Aug 23, 2020
1 parent f1b72c3 commit 434c19d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def self.query(query, options={})
end

# make sure field name uses underscore
# escape forward slashes in query
# escape forward slash, but not other Elasticsearch special characters
if query.present?
query = query.gsub(/publicationYear/, "publication_year")
query = query.gsub(/relatedIdentifiers/, "related_identifiers")
Expand Down Expand Up @@ -1839,12 +1839,18 @@ def self.transfer(options={})
# +job_name+:: Acive Job class name of the Job that would be executed on every matched results
def self.loop_through_dois(options={})
size = (options[:size] || 1000).to_i
cursor = options[:cursor] || []
filter = options[:filter] || {}
label = options[:label] || ""
options[:job_name] ||= ""
query = options[:query].presence

if options[:cursor].present?
timestamp, doi = options[:cursor].split(",", 2)
cursor = [timestamp.to_i, doi]
else
cursor = []
end

response = Doi.query(query, filter.merge(page: { size: 1, cursor: [] }))
message = "#{label} #{response.results.total} Dois with #{label}."

Expand Down
8 changes: 7 additions & 1 deletion app/models/other_doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,18 @@ def self.import_by_id(options={})
# +job_name+:: Acive Job class name of the Job that would be executed on every matched results
def self.loop_through_dois(options={})
size = (options[:size] || 1000).to_i
cursor = options[:cursor] || []
filter = options[:filter] || {}
label = options[:label] || ""
options[:job_name] ||= ""
query = options[:query].presence

if options[:cursor].present?
timestamp, doi = options[:cursor].split(",", 2)
cursor = [timestamp.to_i, doi]
else
cursor = []
end

response = OtherDoi.query(query, filter.merge(page: { size: 1, cursor: [] }))
message = "#{label} #{response.results.total} other dois with #{label}."

Expand Down
51 changes: 51 additions & 0 deletions spec/fixtures/vcr_cassettes/Doi/versions/has_versions.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 434c19d

Please sign in to comment.