Skip to content

Commit

Permalink
fix: add work count and childworkcount to rollbar logs (#950)
Browse files Browse the repository at this point in the history
* fix: add work count and childworkcount to rollbar logs

* fix: rubocop errors

* fix: add exceptionhandling for work deleteion like collection task

* fix: rubocop errors
  • Loading branch information
pghorpade authored Jan 12, 2024
1 parent 71e1be1 commit a7e97ce
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Metrics/ClassLength:
- app/uploaders/csv_manifest_validator.rb
- app/indexers/work_indexer.rb
- app/presenters/hyrax/californica_collection_presenter.rb
- app/lib/californica/deleter.rb

Metrics/BlockLength:
Enabled: true
Expand Down
18 changes: 15 additions & 3 deletions app/lib/californica/deleter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def delete
def delete_collection_with_works(of_type: nil)
log('In delete_collection_with_works start.')
works = work_id_list
log("Number of works in collection #{id}: #{works.count}") # Log the number of works
all_works_deleted = works.empty? || delete_works(of_type: of_type)
if all_works_deleted && (of_type.nil? || record.is_a?(of_type))
delete
Expand All @@ -43,9 +44,7 @@ def delete_works(of_type: nil)
# Modified to ensure all works are deleted before deleting the collection
def delete_with_children(of_type: nil)
log('In delete_with_children start.')
children = record&.member_ids
all_children_deleted = children.nil? || children.empty? || delete_children(of_type: of_type)
if all_children_deleted && (of_type.nil? || record.is_a?(of_type))
if can_delete_with_children?(of_type)
delete
true
else
Expand All @@ -64,6 +63,19 @@ def delete_children(of_type: nil)

private

def can_delete_with_children?(of_type)
children_deleted_or_none?(of_type) && deletion_type_matches?(of_type)
end

def children_deleted_or_none?(of_type)
children = record&.member_ids
children.nil? || children.empty? || delete_children(of_type: of_type)
end

def deletion_type_matches?(of_type)
of_type.nil? || record.is_a?(of_type)
end

def destroy_and_eradicate
start_time = Time.current
record&.destroy&.eradicate
Expand Down
8 changes: 7 additions & 1 deletion lib/tasks/delete.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

namespace :californica do
task delete_work: [:environment] do
Californica::Deleter.new(id: ENV.fetch('DELETE_WORK_ID')).delete_with_children
begin
deletion_successful = Californica::Deleter.new(id: ENV.fetch('DELETE_WORK_ID')).delete_with_children
puts deletion_successful ? 'Deletion completed successfully!' : 'Deletion skipped for some items.'
rescue => e
puts "An error occurred: #{e.message}"
end

puts('Done!')
end

Expand Down

0 comments on commit a7e97ce

Please sign in to comment.