-
Notifications
You must be signed in to change notification settings - Fork 8
/
index_after_job.rb
31 lines (28 loc) · 1.05 KB
/
index_after_job.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# TODO: delete with dual boot cleanup - nested indexing is replaced by graph indexer
module Bulkrax
class IndexAfterJob < ApplicationJob
queue_as :import
def perform(importer)
# check if importer is done, otherwise reschedule
pending_num = importer.entries.left_outer_joins(:latest_status)
.where('bulkrax_statuses.status_message IS NULL ').count
return reschedule(importer.id) unless pending_num.zero?
# read queue and index objects
set = Hyrax.config.redis_connection.zpopmax("nested:index:#{importer.id}", 100)
logger.debug(set.to_s)
return if set.blank?
loop do
set.each do |key, score|
Hyrax.config.nested_relationship_reindexer.call(id: key, extent: 'full')
end
set = Hyrax.config.redis_connection.zpopmax("nested:index:#{importer.id}", 100)
logger.debug(set.to_s)
break if set.blank?
end
end
def reschedule(importer_id)
Bulkrax::IndexAfterJob.set(wait: 1.minutes).perform_later(importer_id: importer_id)
false
end
end
end