-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1991 from samvera/index_job_tidying
make indexing records more resiliant and uniform
- Loading branch information
Showing
6 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |