mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-24 01:49:42 -04:00
fix more
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from flask import current_app
|
||||
from sqlalchemy import between
|
||||
from sqlalchemy import between, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from app import notify_celery, zendesk_client
|
||||
from app import db, notify_celery, zendesk_client
|
||||
from app.celery.tasks import (
|
||||
get_recipient_csv_and_template_and_sender_id,
|
||||
process_incomplete_jobs,
|
||||
@@ -105,14 +105,28 @@ def check_job_status():
|
||||
thirty_minutes_ago = utc_now() - timedelta(minutes=30)
|
||||
thirty_five_minutes_ago = utc_now() - timedelta(minutes=35)
|
||||
|
||||
incomplete_in_progress_jobs = Job.query.filter(
|
||||
Job.job_status == JobStatus.IN_PROGRESS,
|
||||
between(Job.processing_started, thirty_five_minutes_ago, thirty_minutes_ago),
|
||||
incomplete_in_progress_jobs = (
|
||||
db.session.execute(
|
||||
select(Job).where(
|
||||
Job.job_status == JobStatus.IN_PROGRESS,
|
||||
between(
|
||||
Job.processing_started, thirty_five_minutes_ago, thirty_minutes_ago
|
||||
),
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
incomplete_pending_jobs = Job.query.filter(
|
||||
Job.job_status == JobStatus.PENDING,
|
||||
Job.scheduled_for.isnot(None),
|
||||
between(Job.scheduled_for, thirty_five_minutes_ago, thirty_minutes_ago),
|
||||
incomplete_pending_jobs = (
|
||||
db.session.execute(
|
||||
select(Job).where(
|
||||
Job.job_status == JobStatus.PENDING,
|
||||
Job.scheduled_for.isnot(None),
|
||||
between(Job.scheduled_for, thirty_five_minutes_ago, thirty_minutes_ago),
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
|
||||
jobs_not_complete_after_30_minutes = (
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from sqlalchemy import select
|
||||
|
||||
from app import create_uuid, db
|
||||
from app.dao.dao_utils import autocommit, version_class
|
||||
from app.enums import CallbackType
|
||||
from app.models import ServiceCallbackApi
|
||||
from app.utils import utc_now
|
||||
from sqlalchemy import select
|
||||
|
||||
|
||||
@autocommit
|
||||
@version_class(ServiceCallbackApi)
|
||||
@@ -29,23 +31,41 @@ def reset_service_callback_api(
|
||||
|
||||
|
||||
def get_service_callback_api(service_callback_api_id, service_id):
|
||||
return db.session.execute(select(ServiceCallbackApi).filter_by(
|
||||
id=service_callback_api_id, service_id=service_id
|
||||
)).scalars().first()
|
||||
return (
|
||||
db.session.execute(
|
||||
select(ServiceCallbackApi).filter_by(
|
||||
id=service_callback_api_id, service_id=service_id
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.first()
|
||||
)
|
||||
|
||||
|
||||
def get_service_delivery_status_callback_api_for_service(service_id):
|
||||
return db.session.execute(select(ServiceCallbackApi).filter_by(
|
||||
service_id=service_id,
|
||||
callback_type=CallbackType.DELIVERY_STATUS,
|
||||
)).scalars().first()
|
||||
return (
|
||||
db.session.execute(
|
||||
select(ServiceCallbackApi).filter_by(
|
||||
service_id=service_id,
|
||||
callback_type=CallbackType.DELIVERY_STATUS,
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.first()
|
||||
)
|
||||
|
||||
|
||||
def get_service_complaint_callback_api_for_service(service_id):
|
||||
return db.session.execute(select(ServiceCallbackApi).filter_by(
|
||||
service_id=service_id,
|
||||
callback_type=CallbackType.COMPLAINT,
|
||||
)).scalars().first()
|
||||
return (
|
||||
db.session.execute(
|
||||
select(ServiceCallbackApi).filter_by(
|
||||
service_id=service_id,
|
||||
callback_type=CallbackType.COMPLAINT,
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.first()
|
||||
)
|
||||
|
||||
|
||||
@autocommit
|
||||
|
||||
@@ -2,10 +2,12 @@ import itertools
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from flask import Blueprint, current_app, jsonify, request
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from werkzeug.datastructures import MultiDict
|
||||
|
||||
from app import db
|
||||
from app.aws.s3 import get_personalisation_from_s3, get_phone_number_from_s3
|
||||
from app.config import QueueNames
|
||||
from app.dao import fact_notification_status_dao, notifications_dao
|
||||
@@ -419,14 +421,26 @@ def get_service_history(service_id):
|
||||
template_history_schema,
|
||||
)
|
||||
|
||||
service_history = Service.get_history_model().query.filter_by(id=service_id).all()
|
||||
service_history = (
|
||||
db.session.execute(select(Service.get_history_model()).filter_by(id=service_id))
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
service_data = service_history_schema.dump(service_history, many=True)
|
||||
api_key_history = (
|
||||
ApiKey.get_history_model().query.filter_by(service_id=service_id).all()
|
||||
db.session.execute(
|
||||
select(ApiKey.get_history_model()).filter_by(service_id=service_id)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
api_keys_data = api_key_history_schema.dump(api_key_history, many=True)
|
||||
|
||||
template_history = TemplateHistory.query.filter_by(service_id=service_id).all()
|
||||
template_history = (
|
||||
db.session.execute(select(TemplateHistory).filter_by(service_id=service_id))
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
template_data = template_history_schema.dump(template_history, many=True)
|
||||
|
||||
data = {
|
||||
|
||||
Reference in New Issue
Block a user