mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
merge from main
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
|
||||
from flask import current_app
|
||||
from sqlalchemy import asc, desc, func
|
||||
from sqlalchemy import desc, func
|
||||
|
||||
from app import db
|
||||
from app.dao.dao_utils import autocommit
|
||||
@@ -33,20 +33,6 @@ def dao_get_provider_versions(provider_id):
|
||||
)
|
||||
|
||||
|
||||
def _adjust_provider_priority(provider, new_priority):
|
||||
current_app.logger.info(
|
||||
f"Adjusting provider priority - {provider.identifier} going from {provider.priority} to {new_priority}"
|
||||
)
|
||||
provider.priority = new_priority
|
||||
|
||||
# Automatic update so set as notify user
|
||||
provider.created_by_id = current_app.config["NOTIFY_USER_ID"]
|
||||
|
||||
# update without commit so that both rows can be changed without ending the transaction
|
||||
# and releasing the for_update lock
|
||||
_update_provider_details_without_commit(provider)
|
||||
|
||||
|
||||
def _get_sms_providers_for_update(time_threshold):
|
||||
"""
|
||||
Returns a list of providers, while holding a for_update lock on the provider details table, guaranteeing that those
|
||||
@@ -86,11 +72,7 @@ def get_provider_details_by_notification_type(
|
||||
if supports_international:
|
||||
filters.append(ProviderDetails.supports_international == supports_international)
|
||||
|
||||
return (
|
||||
ProviderDetails.query.filter(*filters)
|
||||
.order_by(asc(ProviderDetails.priority))
|
||||
.all()
|
||||
)
|
||||
return ProviderDetails.query.filter(*filters).all()
|
||||
|
||||
|
||||
@autocommit
|
||||
@@ -135,7 +117,6 @@ def dao_get_provider_stats():
|
||||
ProviderDetails.id,
|
||||
ProviderDetails.display_name,
|
||||
ProviderDetails.identifier,
|
||||
ProviderDetails.priority,
|
||||
ProviderDetails.notification_type,
|
||||
ProviderDetails.active,
|
||||
ProviderDetails.updated_at,
|
||||
@@ -149,7 +130,6 @@ def dao_get_provider_stats():
|
||||
.outerjoin(User, ProviderDetails.created_by_id == User.id)
|
||||
.order_by(
|
||||
ProviderDetails.notification_type,
|
||||
ProviderDetails.priority,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user