Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix delete_records slack formatting #3363

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion catalog/dags/database/delete_records/delete_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ def delete_records_from_media_table(


@task
def notify_slack(text: str) -> str:
def notify_slack(deleted_records_count: int, table_name: str, select_query: str) -> str:
"""Send a message to Slack."""
text = (
f"Deleted {deleted_records_count:,} records from the"
f" `{table_name}` table matching query: `{select_query}`"
)
slack.send_message(
text,
username=constants.SLACK_USERNAME,
Expand Down
7 changes: 3 additions & 4 deletions catalog/dags/database/delete_records/delete_records_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ def delete_records():
)(table="{{ params.table_name }}", select_query="{{ params.select_query }}")

notify_complete = notify_slack(
text=(
f"Deleted {delete_records} records from the"
" {{ params.table_name }} table matching query: `{{ params.select_query }}`"
),
deleted_records_count=delete_records,
table_name="{{ params.table_name }}",
select_query="{{ params.select_query }}",
)

insert_into_deleted_media_table >> delete_records >> notify_complete
Expand Down
9 changes: 9 additions & 0 deletions catalog/tests/dags/database/test_delete_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from database.delete_records.delete_records import (
create_deleted_records,
delete_records_from_media_table,
notify_slack,
)


Expand Down Expand Up @@ -246,3 +247,11 @@ def test_delete_no_records_from_media_table(

# All three records are left in the image table
assert len(actual_rows) == 3


def test_notify_slack():
message = notify_slack.function(123456789, "audio", "WHERE provider='foo';")
assert message == (
"Deleted 123,456,789 records from the `audio` table matching query: "
"`WHERE provider='foo';`"
)