mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-04 05:30:53 -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,15 +105,18 @@ 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(
|
||||
stmt = select(Job).where(
|
||||
Job.job_status == JobStatus.IN_PROGRESS,
|
||||
between(Job.processing_started, thirty_five_minutes_ago, thirty_minutes_ago),
|
||||
)
|
||||
incomplete_pending_jobs = Job.query.filter(
|
||||
incomplete_in_progress_jobs = db.session.execute(stmt).scalars().all()
|
||||
|
||||
stmt = select(Job).where(
|
||||
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(stmt).scalars().all()
|
||||
|
||||
jobs_not_complete_after_30_minutes = (
|
||||
incomplete_in_progress_jobs.union(incomplete_pending_jobs)
|
||||
|
||||
@@ -646,8 +646,9 @@ def populate_annual_billing_with_defaults(year, missing_services_only):
|
||||
This is useful to ensure all services start the new year with the correct annual billing.
|
||||
"""
|
||||
if missing_services_only:
|
||||
active_services = (
|
||||
Service.query.filter(Service.active)
|
||||
stmt = (
|
||||
select(Service)
|
||||
.where(Service.active)
|
||||
.outerjoin(
|
||||
AnnualBilling,
|
||||
and_(
|
||||
@@ -656,10 +657,11 @@ def populate_annual_billing_with_defaults(year, missing_services_only):
|
||||
),
|
||||
)
|
||||
.filter(AnnualBilling.id == None) # noqa
|
||||
.all()
|
||||
)
|
||||
active_services = db.session.execute(stmt).scalars().all()
|
||||
else:
|
||||
active_services = Service.query.filter(Service.active).all()
|
||||
stmt = select(Service).where(Service.active)
|
||||
active_services = db.session.execute(stmt).scalars().all()
|
||||
previous_year = year - 1
|
||||
services_with_zero_free_allowance = (
|
||||
db.session.query(AnnualBilling.service_id)
|
||||
|
||||
Reference in New Issue
Block a user