Merge pull request #1284 from GSA/notify-admin-1859

Fix job.created_at time if necessary
This commit is contained in:
Carlo Costino
2024-08-20 16:25:09 -04:00
committed by GitHub
2 changed files with 21 additions and 4 deletions

View File

@@ -1,3 +1,4 @@
import os
import uuid
from datetime import timedelta
@@ -140,6 +141,25 @@ def dao_create_job(job):
job.id = uuid.uuid4()
db.session.add(job)
db.session.commit()
# We are seeing weird time anomalies where a job can be created on
# 8/19 yet show a created_at time of 8/16. This seems to be the only
# place the created_at value is set so do some double-checking and debugging
orig_time = job.created_at
now_time = utc_now()
diff_time = now_time - orig_time
current_app.logger.info(
f"#notify-admin-1859 dao_create_job orig created at {orig_time} and now {now_time}"
)
if diff_time.total_seconds() > 300: # It should be only a few seconds diff at most
current_app.logger.error(
"#notify-admin-1859 Something is wrong with job.created_at!"
)
if os.getenv("NOTIFY_ENVIRONMENT") not in ["test"]:
job.created_at = now_time
dao_update_job(job)
current_app.logger.error(
f"#notify-admin-1859 Job created_at reset to {job.created_at}"
)
def dao_update_job(job):