Skip to content

Commit

Permalink
refact: move notifications to send_upgrade_notification fn
Browse files Browse the repository at this point in the history
The idea being that the function gets re-used if/when necessary
  • Loading branch information
n-dusan committed Jul 31, 2024
1 parent 1edec34 commit e5c0e11
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions upgrade/scripts/upgrade_python_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,11 @@ def install_wheel(
)
except:
if slack_webhook_url is not None:
try:
environment = (
"dev" if is_development_cloudsmith(cloudsmith_url) else "prod"
)
log_filepath = get_log_file_path().as_posix() or "log file"
server_metadata = get_server_metadata()
send_slack_notification(
f"Failed to upgrade package {package_name}",
f"{environment.upper()} - For more details, please audit {str(log_filepath)} at ({server_metadata}).",
slack_webhook_url,
)
except Exception as e:
logging.error(
f"Failed to send slack notification due to error: {e}"
)
raise
send_upgrade_notification(
f"Failed to upgrade package {package_name}",
cloudsmith_url,
slack_webhook_url,
)
# if install with constraints fails or the installation caused broken dependencies
# revert back to old package version
if version is not None:
Expand Down Expand Up @@ -437,6 +426,22 @@ def run_module_and_reload_uwsgi_app(module_name, *args):
reload_uwsgi_app(package_name)


def send_upgrade_notification(header, cloudsmith_url, slack_webhook_url):
try:
log_filepath = get_log_file_path().as_posix() or "log file"
server_metadata = get_server_metadata()
environment = "dev" if is_development_cloudsmith(cloudsmith_url) else "prod"
text = f"{environment.upper()} - For more details, please audit {str(log_filepath)} at ({server_metadata})."
send_slack_notification(
header,
text,
slack_webhook_url,
)
except Exception as e:
logging.error(f"Failed to send upgrade notification due to error: {e}")
raise


def split_package_name_and_extra(package_install_cmd):
extra_start = package_install_cmd.find("[")
if extra_start != -1:
Expand Down

0 comments on commit e5c0e11

Please sign in to comment.