Skip to content

Commit

Permalink
Feil med fil-arkivering #38
Browse files Browse the repository at this point in the history
  • Loading branch information
heming-langrenn committed Dec 3, 2024
1 parent faf78ae commit 5be4ffd
Show file tree
Hide file tree
Showing 4 changed files with 779 additions and 728 deletions.
13 changes: 10 additions & 3 deletions photo_service_gui/services/events_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ async def sync_events(self, token: str, remote_url: str) -> str:
"""Import events from remote server and store in local db."""
servicename = "sync_events"
information = "Importerer events."
current_events = await self.get_all_events(token)
current_event_ids = []
for event in current_events:
current_event_ids.append(event["id"])


headers = MultiDict(
[
(hdrs.AUTHORIZATION, f"Bearer {token}"),
Expand All @@ -162,9 +168,10 @@ async def sync_events(self, token: str, remote_url: str) -> str:
# import events to local database
if events:
for event in events:
information += await EventsAdapter().create_event(
token, event
)
if event["id"] not in current_event_ids:
information += await EventsAdapter().create_event(
token, event
)
elif resp.status == 401:
raise web.HTTPBadRequest(reason=f"401 Unathorized - {servicename}")
else:
Expand Down
18 changes: 11 additions & 7 deletions photo_service_gui/services/foto_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,17 @@ async def push_new_photos_from_file(self, token: str, event: dict) -> str:
logging.error(error_text)
raise Exception(error_text) from e

# archive photos
PhotosFileAdapter().move_photo_to_archive(
os.path.basename(group["main"])
)
PhotosFileAdapter().move_photo_to_archive(
os.path.basename(group["crop"])
)
# archive photos - ignore errors
try:
PhotosFileAdapter().move_photo_to_archive(
os.path.basename(group["main"])
)
PhotosFileAdapter().move_photo_to_archive(
os.path.basename(group["crop"])
)
except Exception as e:
error_text = f"Error moving files to archive {e}"
logging.error(error_text)

logging.debug(f"Published message {result} to pubsub.")
i_photo_count += 1
Expand Down
Loading

0 comments on commit 5be4ffd

Please sign in to comment.