Skip to content

Commit

Permalink
Merge pull request #913 from DalgoT4D/notifications-tweaks
Browse files Browse the repository at this point in the history
Notifications tweaks
  • Loading branch information
Ishankoradia authored Dec 7, 2024
2 parents 530d8c8 + 71187eb commit a9f3ce9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ddpui/api/webhook_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def post_notification_v1(request): # pylint: disable=unused-argument
notify_platform_admins(org, flow_run["id"], state)
notify_org_managers(
org,
f"A job for \"{name_of_deployment}\" of type \"{type_of_deployment}\" has failed, please visit {os.getenv('FRONTEND_URL')} for more details",
f"To the admins of {org.name},\n\nA job for \"{name_of_deployment}\" of type \"{type_of_deployment}\" has failed, please visit {os.getenv('FRONTEND_URL')} for more details",
)
email_orgusers_ses_whitelisted(
org,
Expand Down
8 changes: 7 additions & 1 deletion ddpui/celeryworkers/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,15 @@ def detect_schema_changes_for_org(org: Org):
# notify users
if change_type in ["breaking", "non_breaking"]:
try:
frontend_url = os.getenv("FRONTEND_URL")
if frontend_url.endswith("/"):
frontend_url = frontend_url[:-1]
connections_page = f"{frontend_url}/pipeline/ingest?tab=connections"
notify_org_managers(
org,
"This email is to let you know that schema changes have been detected in your Dalgo pipeline, which require your review.",
f"To the admins of {org.name},\n\nThis email is to let you know that"
" schema changes have been detected in your Dalgo sources.\n\nPlease"
f" visit {connections_page} and review the Pending Actions",
)
except Exception as err:
logger.error(err)
Expand Down
6 changes: 4 additions & 2 deletions ddpui/core/notifications_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ddpui.models.org_preferences import OrgPreferences
from ddpui.utils import timezone
from ddpui.utils.discord import send_discord_notification
from ddpui.utils.sendgrid import send_email_notification
from ddpui.utils.awsses import send_text_message
from ddpui.schemas.notifications_api_schemas import SentToEnum, NotificationDataSchema
from ddpui.celeryworkers.moretasks import schedule_notification_task

Expand Down Expand Up @@ -83,7 +83,9 @@ def handle_recipient(

if user_preference.enable_email_notifications:
try:
send_email_notification(user_preference.orguser.user.email, notification.message)
send_text_message(
user_preference.orguser.user.email, "Message from Dalgo", notification.message
)
except Exception as e:
return {
"recipient": notification_recipient.recipient.user.email,
Expand Down
6 changes: 5 additions & 1 deletion ddpui/tests/core/test_celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def test_detect_schema_changes_for_org_send_schema_changes_email(
)
OrgSchemaChange.objects.create(org=org_without_workspace, connection_id="fake-connection-id")
assert OrgSchemaChange.objects.filter(org=org_without_workspace).count() == 1
os.environ["FRONTEND_URL"] = "http://localhost:3000"
with patch(
"ddpui.ddpairbyte.airbytehelpers.fetch_and_update_org_schema_changes"
) as fetch_and_update_org_schema_changes_mock, patch(
Expand All @@ -392,9 +393,12 @@ def test_detect_schema_changes_for_org_send_schema_changes_email(
orguser.save()
detect_schema_changes_for_org(org_without_workspace)
assert OrgSchemaChange.objects.filter(org=org_without_workspace).count() == 0

connections_page = "http://localhost:3000/pipeline/ingest?tab=connections"

notify_org_managers_mock.assert_called_once_with(
org_without_workspace,
"""This email is to let you know that schema changes have been detected in your Dalgo pipeline, which require your review.""",
f"To the admins of {org_without_workspace.name},\n\nThis email is to let you know that schema changes have been detected in your Dalgo sources.\n\nPlease visit {connections_page} and review the Pending Actions",
)


Expand Down

0 comments on commit a9f3ce9

Please sign in to comment.