Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleter-handle-solr-error #961

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions app/lib/californica/deleter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def initialize(id: nil, record: nil, logger: Rails.logger)
end

def delete
log("Californica::Deleter.delete: deleting #{@id}")
destroy_and_eradicate
end

Expand All @@ -36,8 +37,9 @@ def delete_collection_with_works(of_type: nil)
# Ensures all works are deleted; returns true if successful
def delete_works(of_type: nil)
work_id_list.empty? || work_id_list.all? do |work_id|
log("Californica::Deleter.delete_works: deleting work #{work_id}")
Californica::Deleter.new(id: work_id, logger: logger)
.delete_with_children(of_type: of_type)
.delete(of_type: of_type)
end
end

Expand Down Expand Up @@ -77,17 +79,19 @@ def deletion_type_matches?(of_type)
end

def destroy_and_eradicate
log("Californica::Deleter.destroy_and_eradicate: #{@id}")
start_time = Time.current
record&.destroy&.eradicate
Hyrax.config.callback.run(:after_destroy, record.id, User.batch_user)
log("Deleted #{record.class} #{record.id} in #{ActiveSupport::Duration.build(Time.current - start_time)}")
log("deleted item ark is: #{record.ark}")
rescue Ldp::HttpError, Faraday::TimeoutError, Faraday::ConnectionFailed => e
rescue Ldp::HttpError, Faraday::TimeoutError, Faraday::ConnectionFailed, RSolr::Error::Http => e
log("#{e.class}: #{e.message}")
retries ||= 0
if (retries += 1) > 3
return false # Explicitly return false after retries are exhausted
else
sleep(10**(retries - 1))
retry
end
end
Expand All @@ -96,6 +100,7 @@ def delete_from_fcrepo
ActiveFedora.fedora.connection.delete(ActiveFedora::Base.id_to_uri(id))
log("Forced delete of record from Fedora")
rescue Ldp::NotFound
log("Record not found in Fedora")
nil # Everything's good, we just wanted to make sure there wasn't a record in fedora not indexed to solr
end

Expand All @@ -111,7 +116,8 @@ def log(message, status: :info)
def record
@record ||= ActiveFedora::Base.find(id)

rescue ActiveFedora::ObjectNotFoundError
rescue ActiveFedora::ObjectNotFoundError => e
log(e, status: :error)
delete_from_fcrepo
end

Expand Down
Loading