Edit Order Notification Technical Design

Overview

Edit Order Notifications polls a view in Google Big Query to obtain a list of customer orders that are due for delivery the next working day. For each of the customer orders found, we need to query the Morissons Customer system to obtain the customer email address and mobile phone number. If we have a valid email we will call the marketing SPI to send an email reminder to the customer. Similarly if we have a mobile phone number we will send a SMS reminder through the marketing API. The status of the application is monitored through a Big Query report table and Datadog metrics.

References

Document

Ref

Business Analysis Pages

Business Analysis.

Architecture Document

Solution Architecture.

Jira Epic

Edit Order Notification: SPDP-721.

Main Jira Story

Edit Order Notification: SPDP-722.

Main Jira Story

Edit Order Reporting: SPDP-1037.

Sequence Diagram

@startuml

title Edit Order Notification

skinparam participant {

	BackgroundColor<<NEW>> DarkSeaGreen
	BorderColor<<NEW>> DarkSlateGray
	CardFontColor<<NEW>> white

	BackgroundColor<<NEW>> DarkSeaGreen
	BorderColor<<NEW>> DarkSlateGray
	CardFontColor<<NEW>> white

	ArrowColor Olive
}

Actor "CloudWatch cron" as CloudWatchTrigger

participant "<<AWS ECS Task>>\nEmail Notification Task" as AWSECSEmailNotification << NEW >>
participant "<<class>>\n<pymorri>\nSSM" as ssm_reader
participant "<<class>>\n<pymorri>\nConfigReader2" as config_reader
participant "<<BigQuery View>>\nEdit Cutoff Time Tomorrow" as BQEONView <<NEW>>
participant "<pymorri>\nMorissons Customer API" as MoriCustomer << NEW >>
participant "<<pymorri>>\nMorissons Marketing API" as MoriMarketing << NEW >>
participant "<<list>>\nreport list" as list
participant "<<Monitoring Service>>\nDatadog monitoring" as Monitoring << NEW >>
participant "<<BigQuery Table>>\nEdit Order Notification Report" as BQEONReport << NEW >>

Actor "OSP Customer" as OSPCustomer

CloudWatchTrigger -> AWSECSEmailNotification : cron daily at 9am

== Initialise ECS Task ==

AWSECSEmailNotification -> ssm_reader : Read Config credentials from SSM
ssm_reader -> AWSECSEmailNotification : JSON object with config credentials
AWSECSEmailNotification -> config_reader : Read application configuration from \nstorepick-email-notification-app.json
config_reader -> AWSECSEmailNotification : JSON object with app config

== End Initialise ECS Task ==

AWSECSEmailNotification -> BQEONView : Retrieve view 'edit_cutoff_time_tomorrow'
BQEONView -> AWSECSEmailNotification : return JSON payload containing customer orders

group loop CustomerOrder

    == Process Notification ==
       AWSECSEmailNotification -> MoriCustomer : retrieve customer details
       AWSECSEmailNotification -> AWSECSEmailNotification : extract email and phone number
       AWSECSEmailNotification -> AWSECSEmailNotification : validate email (simple, does it contain '@' and is it a reasonable length)
       AWSECSEmailNotification -> AWSECSEmailNotification : validate phone number (simple, length and numeric)\n strip leading '+'\nreplace leading '0' with '44'

       AWSECSEmailNotification -> MoriMarketing : POST /channels/email/{templateId}
       alt If response.status != 200
            AWSECSEmailNotification -> list : add entry to report list
            AWSECSEmailNotification -> Monitoring : add result to monitoring
       else
            AWSECSEmailNotification -> list : add entry to report list
            AWSECSEmailNotification -> Monitoring : add result to monitoring
       end

       AWSECSEmailNotification -> MoriMarketing : POST /channels/sms
       alt If response.status != 200
            AWSECSEmailNotification -> list : add entry to report list
            AWSECSEmailNotification -> Monitoring : add result to monitoring
       else
            AWSECSEmailNotification -> list : add entry to report list
            AWSECSEmailNotification -> Monitoring : add result to monitoring
       end

    == End Process Notification ==

end 'CustomerOrder'

== Write control file to assist testing ==

'AWSLambda -> s3_file_operations : write control list to <s3_bucket>/processing
's3_file_operations <-> S3 : write list as csv to S3
's3_file_operations -> AWSLambda : file successfully written

== Write report on processing ==

AWSECSEmailNotification -> AWSECSEmailNotification : Prepare report summary list\nready for big query
AWSECSEmailNotification -> BQEONReport : Write report details to 'Edit_Order_Notification_Report'

'AWSLambda -> s3_file_operations : write control list to <s3_bucket>/processing
's3_file_operations <-> S3 : write list as csv to S3
's3_file_operations -> AWSLambda : file successfully written

== What to do here.... NOT_IMPLEMENTED ==

alt If ECSTask.status != 200
' This may be written to BQ
    AWSECSEmailNotification -> Log : Failure
    AWSECSEmailNotification -> Monitoring : Failure

else
    AWSECSEmailNotification -> Log : Success
    AWSECSEmailNotification -> Monitoring : Success
end

AWSECSEmailNotification -> CloudWatchTrigger : notifications successfully processed

@enduml