Skip to content

Commit

Permalink
Merge pull request #19 from infn-datacloud/catch-connection-error
Browse files Browse the repository at this point in the history
Catch ConnectionError when fed-reg is not available
  • Loading branch information
giosava94 authored Sep 9, 2024
2 parents 5f15f6e + 6116c6c commit 97dd8b8
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import yaml
from fed_reg.provider.schemas_extended import ProviderCreateExtended
from requests.exceptions import ConnectionError

from src.config import Settings, URLs
from src.crud import CRUD
Expand Down Expand Up @@ -113,14 +114,19 @@ def update_database(
)

logger.info("Retrieving data from Federation-Registry")
db_items = {db_item.name: db_item for db_item in crud.read()}
for item in items:
db_item = db_items.pop(item.name, None)
if db_item is None or db_item.type != item.type:
crud.create(data=item)
else:
crud.update(new_data=item, old_data=db_item)
for db_item in db_items.values():
crud.remove(item=db_item)
try:
db_items = {db_item.name: db_item for db_item in crud.read()}
for item in items:
db_item = db_items.pop(item.name, None)
if db_item is None or db_item.type != item.type:
crud.create(data=item)
else:
crud.update(new_data=item, old_data=db_item)
for db_item in db_items.values():
crud.remove(item=db_item)
except ConnectionError as e:
logger.error("Can't connect to Federation Registry.")
logger.error(e)
return True

return crud.error

0 comments on commit 97dd8b8

Please sign in to comment.