mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Merge branch 'master' into populate-monthly-letter-usages
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timedelta, time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from flask import current_app
|
||||
|
||||
@@ -85,7 +85,7 @@ def upload_letters_pdf(reference, crown, filedata):
|
||||
now = datetime.utcnow()
|
||||
|
||||
print_datetime = now
|
||||
if now.time() > time(17, 30):
|
||||
if now.time() > current_app.config.get('LETTER_PROCESSING_DEADLINE'):
|
||||
print_datetime = now + timedelta(days=1)
|
||||
|
||||
upload_file_name = LETTERS_PDF_FILE_LOCATION_STRUCTURE.format(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import (
|
||||
date,
|
||||
datetime,
|
||||
timedelta
|
||||
)
|
||||
@@ -33,6 +34,7 @@ from app.dao.notifications_dao import (
|
||||
dao_timeout_notifications,
|
||||
is_delivery_slow_for_provider,
|
||||
delete_notifications_created_more_than_a_week_ago_by_type,
|
||||
dao_get_count_of_letters_to_process_for_date,
|
||||
dao_get_scheduled_notifications,
|
||||
set_scheduled_notification_to_processed,
|
||||
dao_set_created_live_letter_api_notifications_to_pending,
|
||||
@@ -355,6 +357,20 @@ def run_letter_jobs():
|
||||
current_app.logger.info("Queued {} ready letter job ids onto {}".format(len(job_ids), QueueNames.PROCESS_FTP))
|
||||
|
||||
|
||||
@notify_celery.task(name="trigger-letter-pdfs-for-day")
|
||||
@statsd(namespace="tasks")
|
||||
def trigger_letter_pdfs_for_day():
|
||||
letter_pdfs_count = dao_get_count_of_letters_to_process_for_date()
|
||||
if letter_pdfs_count:
|
||||
notify_celery.send_task(
|
||||
name='collate-letter-pdfs-for-day',
|
||||
args=(date.today().strftime("%Y-%m-%d"),),
|
||||
queue=QueueNames.LETTERS
|
||||
)
|
||||
current_app.logger.info("{} letter pdfs to be process by {} task".format(
|
||||
letter_pdfs_count, 'collate-letter-pdfs-for-day'))
|
||||
|
||||
|
||||
@notify_celery.task(name="run-letter-api-notifications")
|
||||
@statsd(namespace="tasks")
|
||||
def run_letter_api_notifications():
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import timedelta
|
||||
from datetime import timedelta, time
|
||||
import os
|
||||
import json
|
||||
|
||||
@@ -32,6 +32,7 @@ class QueueNames(object):
|
||||
PROCESS_FTP = 'process-ftp-tasks'
|
||||
CREATE_LETTERS_PDF = 'create-letters-pdf-tasks'
|
||||
CALLBACKS = 'service-callbacks'
|
||||
LETTERS = 'letter-tasks'
|
||||
|
||||
@staticmethod
|
||||
def all_queues():
|
||||
@@ -48,6 +49,7 @@ class QueueNames(object):
|
||||
QueueNames.NOTIFY,
|
||||
QueueNames.CREATE_LETTERS_PDF,
|
||||
QueueNames.CALLBACKS,
|
||||
QueueNames.LETTERS,
|
||||
]
|
||||
|
||||
|
||||
@@ -238,6 +240,11 @@ class Config(object):
|
||||
'schedule': crontab(hour=17, minute=30),
|
||||
'options': {'queue': QueueNames.PERIODIC}
|
||||
},
|
||||
'trigger-letter-pdfs-for-day': {
|
||||
'task': 'trigger-letter-pdfs-for-day',
|
||||
'schedule': crontab(hour=17, minute=50),
|
||||
'options': {'queue': QueueNames.PERIODIC}
|
||||
},
|
||||
'run-letter-api-notifications': {
|
||||
'task': 'run-letter-api-notifications',
|
||||
'schedule': crontab(hour=17, minute=40),
|
||||
@@ -313,6 +320,8 @@ class Config(object):
|
||||
TEMPLATE_PREVIEW_API_HOST = os.environ.get('TEMPLATE_PREVIEW_API_HOST', 'http://localhost:6013')
|
||||
TEMPLATE_PREVIEW_API_KEY = os.environ.get('TEMPLATE_PREVIEW_API_KEY', 'my-secret-key')
|
||||
|
||||
LETTER_PROCESSING_DEADLINE = time(17, 30)
|
||||
|
||||
|
||||
######################
|
||||
# Config overrides ###
|
||||
|
||||
@@ -584,3 +584,37 @@ def dao_get_last_notification_added_for_job_id(job_id):
|
||||
).first()
|
||||
|
||||
return last_notification_added
|
||||
|
||||
|
||||
def dao_get_count_of_letters_to_process_for_date(date_to_process=None):
|
||||
"""
|
||||
Returns a count of letter notifications for services with letters_as_pdf permission set
|
||||
to be processed today if no argument passed in otherwise will return the count for
|
||||
the date passed in.
|
||||
Records processed today = yesterday 17:30 to today 17:29:59
|
||||
|
||||
Note - services without letters_as_pdf permission will be ignored
|
||||
"""
|
||||
if date_to_process is None:
|
||||
date_to_process = date.today()
|
||||
|
||||
day_before = date_to_process - timedelta(days=1)
|
||||
letter_deadline_time = current_app.config.get('LETTER_PROCESSING_DEADLINE')
|
||||
|
||||
start_datetime = datetime.combine(day_before, letter_deadline_time)
|
||||
end_datetime = start_datetime + timedelta(days=1)
|
||||
|
||||
count_of_letters_to_process_for_date = Notification.query.join(
|
||||
Service
|
||||
).filter(
|
||||
Notification.created_at >= start_datetime,
|
||||
Notification.created_at < end_datetime,
|
||||
Notification.notification_type == LETTER_TYPE,
|
||||
Notification.status == NOTIFICATION_CREATED,
|
||||
Notification.key_type != KEY_TYPE_TEST,
|
||||
Service.permissions.any(
|
||||
ServicePermission.permission == 'letters_as_pdf'
|
||||
)
|
||||
).count()
|
||||
|
||||
return count_of_letters_to_process_for_date
|
||||
|
||||
Reference in New Issue
Block a user