Skip to content

Commit

Permalink
support indexing by client
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 26, 2018
1 parent 9c5301a commit 4e88225
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,11 @@ def self.index(options={})
from_date = options[:from_date].present? ? Date.parse(options[:from_date]) : Date.current
until_date = options[:until_date].present? ? Date.parse(options[:until_date]) : Date.current
index_time = options[:index_time].presence || Time.zone.now.utc.iso8601

client_id = options[:client_id]

# get every day between from_date and until_date
(from_date..until_date).each do |d|
DoiIndexByDayJob.perform_later(from_date: d.strftime("%F"), index_time: index_time)
DoiIndexByDayJob.perform_later(from_date: d.strftime("%F"), index_time: index_time, client_id: client_id)
puts "Queued indexing for DOIs created on #{d.strftime("%F")}."
end
end
Expand All @@ -455,13 +456,17 @@ def self.index_by_day(options={})
return nil unless options[:from_date].present?
from_date = Date.parse(options[:from_date])
index_time = options[:index_time].presence || Time.zone.now.utc.iso8601
client_id = options[:client_id]

errors = 0
count = 0

logger = Logger.new(STDOUT)

Doi.where(created: from_date.midnight..from_date.end_of_day).where("indexed < ?", index_time).find_in_batches(batch_size: 250) do |dois|
collection = Doi.where(created: from_date.midnight..from_date.end_of_day).where("indexed < ?", index_time)
collection = collection.where(client_id: client_id) if client_id.present?

collection.find_in_batches(batch_size: 250) do |dois|
response = Doi.__elasticsearch__.client.bulk \
index: Doi.index_name,
type: Doi.document_type,
Expand Down
3 changes: 2 additions & 1 deletion lib/tasks/doi.rake
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ namespace :doi do
end

index_time = ENV['INDEX_TIME'] || Time.zone.now.utc.iso8601
client_id = ENV['CLIENT_ID']

Doi.index(from_date: from_date, until_date: until_date, index_time: index_time)
Doi.index(from_date: from_date, until_date: until_date, index_time: index_time, client_id: client_id)
end

desc 'Index DOIs per day'
Expand Down

0 comments on commit 4e88225

Please sign in to comment.