Skip to content

Commit

Permalink
make indexing records more resiliant and uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
orangewolf committed Sep 21, 2023
1 parent e60efac commit 5ea9895
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
# limit to 5 attempts
retry_on StandardError, wait: :exponentially_longer, attempts: 5 do |_job, _exception|
# Log error, do nothing, etc.
end
end
3 changes: 1 addition & 2 deletions app/jobs/reindex_collections_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
class ReindexCollectionsJob < ApplicationJob
def perform
Collection.find_each do |collection|
collection.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX)
collection.update_index
ReindexItemJob.perform_later(collection)
end
end
end
9 changes: 9 additions & 0 deletions app/jobs/reindex_file_sets_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class ReindexFileSetsJob < ApplicationJob
def perform
FileSet.find_each do |file_set|
ReindexItemJob.perform_later(file_set)
end
end
end
7 changes: 7 additions & 0 deletions app/jobs/reindex_item_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class ReindexItemJob < ApplicationJob
def perform(item)
item.update_index
end
end
6 changes: 4 additions & 2 deletions app/jobs/reindex_works_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

class ReindexWorksJob < ApplicationJob
def perform
Hyrax.config.registered_curation_concern_types.each do |work_type|
work_type.constantize.find_each(&:update_index)
Site.instance.available_works.each do |work_type|
work_type.constantize.find_each do |work|
ReindexItemJob.perform_later(work)
end
end
end
end
60 changes: 60 additions & 0 deletions lib/tasks/index.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

require 'ruby-progressbar'

desc "reindex just the works in the background"
task index_works: :environment do
Account.find_each do |account|
puts "=============== #{account.name}============"
next if account.name == "search"
switch!(account)
in_each_account do
ReindexWorksJob.perform_later
end
end
end

desc "reindex just the collections in the background"
task index_collections: :environment do
Account.find_each do |account|
puts "=============== #{account.name}============"
next if account.name == "search"
switch!(account)
in_each_account do
ReindexCollectionsJob.perform_later
end
end
end

desc "reindex just the admin_sets in the background"
task index_admin_sets: :environment do
Account.find_each do |account|
puts "=============== #{account.name}============"
next if account.name == "search"
switch!(account)
in_each_account do
ReindexAdminSetsJob.perform_later
end
end
end

desc "reindex just the file_sets in the background"
task index_file_sets: :environment do
Account.find_each do |account|
puts "=============== #{account.name}============"
next if account.name == "search"
switch!(account)
in_each_account do
ReindexFileSetsJob.perform_later
end
end
end

def in_each_account
Account.find_each do |account|
puts "=============== #{account.name}============"
next if account.name == "search"
switch!(account)
yield
end
end

0 comments on commit 5ea9895

Please sign in to comment.