Skip to content

Commit

Permalink
Do not advance timestamp file if log has not been uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
memgonzales committed May 4, 2024
1 parent 013b022 commit b1e68e9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cron_jobs/util/upload_to_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ def prepare_log_file_for_upload():
if get_timestamp(line) > last_uploaded_timestamp:
upload.write(line)

if os.stat(FOR_UPLOAD_LOG_FILE).st_size > 0:
with open(FOR_UPLOAD_LOG_FILE) as upload, open(
LAST_UPLOADED_TIMESTAMP_FILE, "w"
) as timestamp:
for line in upload:
pass

timestamp.write(f"{get_timestamp(line)}")


def upload_log_file():
scope = ["https://www.googleapis.com/auth/drive"]
Expand All @@ -97,6 +88,16 @@ def upload_log_file():
)


def update_last_uploaded_timestamp_file():
with open(FOR_UPLOAD_LOG_FILE) as upload, open(
LAST_UPLOADED_TIMESTAMP_FILE, "w"
) as timestamp:
for line in upload:
pass

timestamp.write(f"{get_timestamp(line)}")


if __name__ == "__main__":
if is_logging_mode():
MAX_RETRIES = 5
Expand All @@ -107,9 +108,10 @@ def upload_log_file():
print("Preparing log file to upload...")
prepare_log_file_for_upload()

print("Uploading log file...")
if os.stat(FOR_UPLOAD_LOG_FILE).st_size > 0:
print("Uploading log file...")
upload_log_file()
update_last_uploaded_timestamp_file()
print("Success!")
else:
print("Nothing to write")
Expand Down

0 comments on commit b1e68e9

Please sign in to comment.