def notify()

in bigquery-jobs-notifier/gcf/main.py [0:0]


def notify(message):

    if to_emails is None or sendgrid_api_key is None:
        print("Email notification skipped as TO_EMAILS or SENDGRID_API_KEY is not set")
        return

    print(f"Sending email to {to_emails}")

    message = Mail(
        from_email='noreply@bigquery-usage-notifier.com',
        to_emails=to_emails,
        subject='An expensive BigQuery job just completed',
        html_content=f'<html><pre>{message}</pre></html>')
    try:
        print(f"Email content {message}")
        sg = SendGridAPIClient(sendgrid_api_key)
        response = sg.send(message)
        print(f"Email status code {response.status_code}")
    except Exception as e:
        print(e)