diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d92ffddcb..70d716899 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -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 diff --git a/app/jobs/reindex_collections_job.rb b/app/jobs/reindex_collections_job.rb index e1ef281ba..422d1c8de 100644 --- a/app/jobs/reindex_collections_job.rb +++ b/app/jobs/reindex_collections_job.rb @@ -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 diff --git a/app/jobs/reindex_file_sets_job.rb b/app/jobs/reindex_file_sets_job.rb new file mode 100644 index 000000000..0e2e7931d --- /dev/null +++ b/app/jobs/reindex_file_sets_job.rb @@ -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 diff --git a/app/jobs/reindex_item_job.rb b/app/jobs/reindex_item_job.rb new file mode 100644 index 000000000..d44051be0 --- /dev/null +++ b/app/jobs/reindex_item_job.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class ReindexItemJob < ApplicationJob + def perform(item) + item.update_index + end +end diff --git a/app/jobs/reindex_works_job.rb b/app/jobs/reindex_works_job.rb index 6aee04ba6..56adcf2d0 100644 --- a/app/jobs/reindex_works_job.rb +++ b/app/jobs/reindex_works_job.rb @@ -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 diff --git a/lib/tasks/index.rake b/lib/tasks/index.rake new file mode 100644 index 000000000..c02885af2 --- /dev/null +++ b/lib/tasks/index.rake @@ -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