Skip to content

Commit

Permalink
alert dev team when pipeline encounters permission errors (#1447)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarosenb authored Oct 3, 2024
1 parent 68ea396 commit d583c7e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Utilities to email users/staff in response to project lifecycle changes."""

from typing import Optional
from django.conf import settings
from django.core.mail import send_mail


def send_project_permissions_alert(project_id: str, version: Optional[int], error: str):
"""
Alert dev team when a project has encountered a permission error during publication.
"""
prj_admins = settings.DEV_PROJECT_ADMINS_EMAIL
for admin in prj_admins:
email_body = f"""
<p>Hello,</p>
<p>
The following project has encountered a permission error during publication:
<br/>
<b>{project_id} - revision {version}</b>
<br/>
</p>
<p>
The error is as follows:<br/>
{error}
</p>
This is a programmatically generated message. Do NOT reply to this message.
"""

send_mail(
"DesignSafe Alert: Published Project has missing files/folders",
email_body,
settings.DEFAULT_FROM_EMAIL,
[admin],
html_message=email_body,
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from designsafe.apps.api.projects_v2.operations.project_archive_operations import (
archive_publication_async,
)
from designsafe.apps.api.projects_v2.operations.project_email_operations import (
send_project_permissions_alert,
)
from designsafe.apps.api.publications_v2.models import Publication
from designsafe.apps.api.publications_v2.elasticsearch import index_publication
from designsafe.apps.data.tasks import agave_indexer
Expand Down Expand Up @@ -420,6 +423,11 @@ def copy_publication_files(
},
queue="indexing",
)

except PermissionError as exc:
logger.error(exc)
send_project_permissions_alert(project_id, version, str(exc))

finally:
os.chmod("/corral-repl/tacc/NHERI/published", 0o555)

Expand Down

0 comments on commit d583c7e

Please sign in to comment.