"""Garcon tasks related to various notifications.""" import boto3 from garcon import task from feed_ingestion.conf.config import BOTO3_CONFIG from feed_ingestion.tasks import check_status @task.decorate(timeout=1000) def notify_new_ms_files(activity, feed_name, date): """Notify about new market share files. Args: activity (ActivityWorker): The activity worker. feed_name (str): Feed name. date (str): Ingestion date YYYY-MM-DD. """ notification_email_body = 'There are new files available for {} {}.' client = boto3.client('ses', config=BOTO3_CONFIG) client.send_email( Source='datarequests@theorchard.com', Destination={ 'ToAddresses': [ 'data-squad@theorchard.com', 'DataAnalyticsDept@theorchard.com']}, Message={ 'Subject': { 'Data': 'New files for {}'.format(feed_name), 'Charset': 'UTF-8'}, 'Body': { 'Text': { 'Data': notification_email_body.format(feed_name, date), 'Charset': 'UTF-8' }}}) @task.decorate(timeout=60) @check_status() def sns_publish_message(activity, feed_name, date, topic, message, subject): """Send SNS messages to specific topic w/subject & message. Assumes AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY are set as env vars Args: activity (ActivityWorker): The swf activity worker. feed_name (str): Feed name of workflow execution for status updates. date (str): Reporting date (YYYY-MM-DD). topic (str): Topic ARN (ex.arn:aws:sns:us-east-1:103233932089:dev_test) message (str): The message you want to send to the topic. Messages must be UTF-8 encoded strings and be at most 4KB in size. subject (str): Optional parameter to be used as the "Subject" line of the email notifications. """ if subject: client = boto3.client('sns', config=BOTO3_CONFIG) client.publish(TopicArn=topic, Message=message, Subject=subject) activity.logger.info('SNS report about update_dim_tables sent')