mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
remove jobs from letter api calls
we now no longer create a job. At the end of the post there is no action, as we don't have any tasks to queue immediately - if it's a real notification it'll get picked up in the evening scheduled task. If it's a test notification, we create it with an initial status of sending so that we can be sure it'll never get picked up - and then we trigger the update-letter-notifications-to-sent-to-dvla task to sent the sent-at/by.
This commit is contained in:
@@ -1,38 +1,15 @@
|
||||
from app import create_random_identifier
|
||||
from app.models import LETTER_TYPE, JOB_STATUS_READY_TO_SEND, Job
|
||||
from app.dao.jobs_dao import dao_create_job
|
||||
from app.models import LETTER_TYPE
|
||||
from app.notifications.process_notifications import persist_notification
|
||||
from app.v2.errors import InvalidRequest
|
||||
from app.variables import LETTER_API_FILENAME
|
||||
|
||||
|
||||
def create_letter_api_job(template):
|
||||
service = template.service
|
||||
if not service.active:
|
||||
raise InvalidRequest('Service {} is inactive'.format(service.id), 403)
|
||||
if template.archived:
|
||||
raise InvalidRequest('Template {} is deleted'.format(template.id), 400)
|
||||
|
||||
job = Job(
|
||||
original_file_name=LETTER_API_FILENAME,
|
||||
service=service,
|
||||
template=template,
|
||||
template_version=template.version,
|
||||
notification_count=1,
|
||||
job_status=JOB_STATUS_READY_TO_SEND,
|
||||
created_by=None
|
||||
)
|
||||
dao_create_job(job)
|
||||
return job
|
||||
|
||||
|
||||
def create_letter_notification(letter_data, template, api_key):
|
||||
def create_letter_notification(letter_data, template, api_key, status):
|
||||
notification = persist_notification(
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
# we only accept addresses_with_underscores from the API (from CSV we also accept dashes, spaces etc)
|
||||
recipient=letter_data['personalisation']['address_line_1'],
|
||||
service=job.service,
|
||||
service=template.service,
|
||||
personalisation=letter_data['personalisation'],
|
||||
notification_type=LETTER_TYPE,
|
||||
api_key_id=api_key.id,
|
||||
@@ -40,6 +17,7 @@ def create_letter_notification(letter_data, template, api_key):
|
||||
job_id=None,
|
||||
job_row_number=None,
|
||||
reference=create_random_identifier(),
|
||||
client_reference=letter_data.get('reference')
|
||||
client_reference=letter_data.get('reference'),
|
||||
status=status
|
||||
)
|
||||
return notification
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from notifications_utils.clients import redis
|
||||
from notifications_utils.recipients import (
|
||||
get_international_phone_info,
|
||||
validate_and_format_phone_number,
|
||||
@@ -11,10 +12,8 @@ from notifications_utils.recipients import (
|
||||
|
||||
from app import redis_store
|
||||
from app.celery import provider_tasks
|
||||
from notifications_utils.clients import redis
|
||||
|
||||
from app.config import QueueNames
|
||||
from app.models import SMS_TYPE, Notification, KEY_TYPE_TEST, EMAIL_TYPE, ScheduledNotification
|
||||
from app.models import SMS_TYPE, Notification, KEY_TYPE_TEST, EMAIL_TYPE, NOTIFICATION_CREATED, ScheduledNotification
|
||||
from app.dao.notifications_dao import (dao_create_notification,
|
||||
dao_delete_notifications_and_history_by_id,
|
||||
dao_created_scheduled_notification)
|
||||
@@ -52,7 +51,8 @@ def persist_notification(
|
||||
client_reference=None,
|
||||
notification_id=None,
|
||||
simulated=False,
|
||||
created_by_id=None
|
||||
created_by_id=None,
|
||||
status=NOTIFICATION_CREATED
|
||||
):
|
||||
notification_created_at = created_at or datetime.utcnow()
|
||||
if not notification_id:
|
||||
@@ -73,7 +73,8 @@ def persist_notification(
|
||||
job_row_number=job_row_number,
|
||||
client_reference=client_reference,
|
||||
reference=reference,
|
||||
created_by_id=created_by_id
|
||||
created_by_id=created_by_id,
|
||||
status=status
|
||||
)
|
||||
|
||||
if notification_type == SMS_TYPE:
|
||||
|
||||
Reference in New Issue
Block a user