mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-15 01:32:20 -05:00
Merge branch 'master' into delete-expired-things
Conflicts: app/celery/tasks.py tests/app/celery/test_tasks.py tests/app/dao/test_notification_dao.py
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from app import create_uuid, DATETIME_FORMAT
|
||||
from app import create_uuid, DATETIME_FORMAT, DATE_FORMAT
|
||||
from app import notify_celery, encryption, firetext_client, aws_ses_client
|
||||
from app.clients.email.aws_ses import AwsSesClientException
|
||||
from app.clients.sms.firetext import FiretextClientException
|
||||
@@ -8,7 +8,8 @@ from app.dao.notifications_dao import (
|
||||
dao_create_notification,
|
||||
dao_update_notification,
|
||||
delete_failed_notifications_created_more_than_a_week_ago,
|
||||
delete_successful_notifications_created_more_than_a_day_ago
|
||||
delete_successful_notifications_created_more_than_a_day_ago,
|
||||
dao_get_notification_statistics_for_service_and_day
|
||||
)
|
||||
from app.dao.jobs_dao import dao_update_job, dao_get_job_by_id
|
||||
from app.dao.users_dao import delete_codes_older_created_more_than_a_day_ago
|
||||
@@ -90,6 +91,27 @@ def delete_invitations():
|
||||
def process_job(job_id):
|
||||
start = datetime.utcnow()
|
||||
job = dao_get_job_by_id(job_id)
|
||||
|
||||
service = job.service
|
||||
|
||||
stats = dao_get_notification_statistics_for_service_and_day(
|
||||
service_id=service.id,
|
||||
day=job.created_at.strftime(DATE_FORMAT)
|
||||
)
|
||||
|
||||
total_sent = 0
|
||||
if stats:
|
||||
total_sent = stats.emails_requested + stats.sms_requested
|
||||
|
||||
if total_sent + job.notification_count > service.limit:
|
||||
job.status = 'sending limits exceeded'
|
||||
job.processing_finished = datetime.utcnow()
|
||||
dao_update_job(job)
|
||||
current_app.logger.info(
|
||||
"Job {} size {} error. Sending limits {} exceeded".format(job_id, job.notification_count, service.limit)
|
||||
)
|
||||
return
|
||||
|
||||
job.status = 'in progress'
|
||||
dao_update_job(job)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user