Skip to content

Commit

Permalink
holding: better delete_standard_holdings_having_no_items
Browse files Browse the repository at this point in the history
* Adds try, exception to delete of holding.

Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep and rerowep committed Feb 24, 2022
1 parent 5c9fcc0 commit 66bf87b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions rero_ils/modules/holdings/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@
@shared_task(ignore_result=True)
def delete_standard_holdings_having_no_items():
"""Removes standard holdings records with no attached items."""
current_app.logger.debug(
"Starting delete_standard_holdings_having_no_items task ...")
es_query = HoldingsSearch() \
.filter('term', holdings_type='standard') \
.filter('term', items_count=0) \
.source('pid')

errors = 0
for hit in es_query.scan():
record = Holding.get_record_by_pid(hit.pid)
record.delete(force=False, dbcommit=True, delindex=True)

current_app.logger.debug("Ending delete_standard_holdings_having_no_items")
msg = f'Number of removed holdings: {es_query.count()}'
set_timestamp('holdings-deletion', msg=msg)
return msg
try:
record.delete(force=False, dbcommit=True, delindex=True)
except Exception as err:
errors += 1
reasons = record.reasons_not_to_delete()
current_app.logger.error(
f'Can not delete standard holding: {hit.pid} {reasons} {err}')

counts = {'count': es_query.count(), 'errors': errors}
set_timestamp(**counts)
return counts

0 comments on commit 66bf87b

Please sign in to comment.