mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-14 23:07:49 -04:00
Add get_count_of_letters_to_process to notifications_dao
- will get the letter notifications from day before >= letter processing deadline (17:30) - letters_as_pdf permission is required in the service
This commit is contained in:
@@ -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}
|
||||
},
|
||||
'run-letter-pdfs': {
|
||||
'task': 'run-letter-pdfs',
|
||||
'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,34 @@ 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=date.today()):
|
||||
"""
|
||||
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
|
||||
"""
|
||||
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