Skip to content

Commit

Permalink
Add UUID to timetracking report s3 key to ensure that each report is … (
Browse files Browse the repository at this point in the history
#2224)

* Add UUID to timetracking report s3 key to ensure that each report is uniquely associated with a request.

* Add uuid encoding.
  • Loading branch information
dbernstein authored Dec 20, 2024
1 parent 13da746 commit 27c3ed7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
from palace.manager.sqlalchemy.model.library import Library
from palace.manager.sqlalchemy.util import get_one
from palace.manager.util.uuid import uuid_encode


def eligible_integrations(
Expand Down Expand Up @@ -148,7 +149,7 @@ def run(self) -> None:
arcname=f"palace-inventory-report-for-library-{file_name_modifier}.csv",
)

uid = uuid.uuid4()
uid = uuid_encode(uuid.uuid4())
key = (
f"{S3Service.DOWNLOADS_PREFIX}/inventory_and_holds/{library.short_name}/"
f"inventory-and-holds-for-library-{file_name_modifier}-{uid}.zip"
Expand Down
5 changes: 3 additions & 2 deletions src/palace/manager/scripts/playtime_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from palace.manager.service.storage.s3 import S3Service
from palace.manager.sqlalchemy.model.time_tracking import PlaytimeEntry, PlaytimeSummary
from palace.manager.util.datetime_helpers import previous_months, utc_now
from palace.manager.util.uuid import uuid_encode

if TYPE_CHECKING:
from sqlalchemy.orm import Query
Expand Down Expand Up @@ -186,9 +187,10 @@ def do_run(self):
email_subject = f"{subject_prefix}Playtime Summaries {formatted_start_date} - {formatted_until_date}"
reporting_name_with_no_spaces = reporting_name.replace(" ", "_") + "-"
link_extension = "csv"
uid = uuid_encode(uuid.uuid4())
linked_file_name = (
f"playtime-summary-{reporting_name_with_no_spaces}"
f"{formatted_start_date}-{formatted_until_date}.{link_extension}"
f"{formatted_start_date}-{formatted_until_date}-{uid}.{link_extension}"
)

# Write to a temporary file so we don't overflow the memory
Expand All @@ -210,7 +212,6 @@ def do_run(self):
)

if recipient:
uid = uuid.uuid4()
key = (
f"{S3Service.DOWNLOADS_PREFIX}/{reporting_name}/"
f"{linked_file_name}"
Expand Down

0 comments on commit 27c3ed7

Please sign in to comment.