Tasks now use the new builder method to construct the DB object.

This commit is contained in:
Martyn Inglis
2016-09-07 13:45:37 +01:00
parent 99250b2248
commit 255ffbd7f6

View File

@@ -133,8 +133,11 @@ def send_sms(self,
return
try:
_save_notification(created_at, notification, notification_id, service_id, SMS_TYPE, api_key_id, key_type)
dao_create_notification(
Notification.from_api_request(
created_at, notification, notification_id, service.id, SMS_TYPE, api_key_id, key_type
)
)
send_sms_to_provider.apply_async((service_id, notification_id), queue='send-sms')
current_app.logger.info(
@@ -168,7 +171,11 @@ def send_email(self, service_id,
return
try:
_save_notification(created_at, notification, notification_id, service_id, EMAIL_TYPE, api_key_id, key_type)
dao_create_notification(
Notification.from_api_request(
created_at, notification, notification_id, service.id, EMAIL_TYPE, api_key_id, key_type
)
)
send_email_to_provider.apply_async((service_id, notification_id), queue='send-email')
@@ -184,25 +191,6 @@ def send_email(self, service_id,
)
def _save_notification(created_at, notification, notification_id, service_id, notification_type, api_key_id, key_type):
notification_db_object = Notification(
id=notification_id,
template_id=notification['template'],
template_version=notification['template_version'],
to=notification['to'],
service_id=service_id,
job_id=notification.get('job', None),
job_row_number=notification.get('row_number', None),
status='created',
created_at=datetime.strptime(created_at, DATETIME_FORMAT),
personalisation=notification.get('personalisation'),
notification_type=notification_type,
api_key_id=api_key_id,
key_type=key_type
)
dao_create_notification(notification_db_object)
def service_allowed_to_send_to(recipient, service):
if not service.restricted:
return True