Skip to content

Commit

Permalink
curation: tasks: send results in email
Browse files Browse the repository at this point in the history
  • Loading branch information
yashlamba authored and slint committed Dec 19, 2024
1 parent da1d885 commit 554c881
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions site/zenodo_rdm/curation/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,39 @@

from celery import shared_task
from flask import current_app
from flask_mail import Message
from invenio_access.permissions import system_identity
from invenio_rdm_records.proxies import current_rdm_records_service as records_service
from invenio_search.engine import dsl

from zenodo_rdm.curation.curators import EURecordCurator

RESULT_EMAIL_BODY = """
EU Record Curation Processed
Finished at: {finished_at}
Processed since: {since}
Total Records Processed: {processed}
Records Failed: {failed}
Records Approved: {approved}
Record IDs Approved:
{records_moved}
"""


def _send_result_email(content):
"""Send curation result as email."""
subject = f"EU Record Curation Processesed {datetime.now().date()}"
body = RESULT_EMAIL_BODY.format(finished_at=datetime.now(timezone.utc), **content)
sender = current_app.config["MAIL_DEFAULT_SENDER"]
admin_email = current_app.config["APP_RDM_ADMIN_EMAIL_RECIPIENT"]
recipients = admin_email
if not isinstance(admin_email, list):
recipients = [admin_email]
mail_ext = current_app.extensions["mail"]
msg = Message(subject, sender=sender, recipients=recipients, body=body)
mail_ext.send(msg)


@shared_task
def run_eu_record_curation(since):
Expand Down Expand Up @@ -82,6 +109,9 @@ def run_eu_record_curation(since):
# This catches failures due to other reasons
ctx["failed"] += 1

if not dry_run:
_send_result_email(ctx)

current_app.logger.error(
"EU curation processed",
extra=ctx,
Expand Down

0 comments on commit 554c881

Please sign in to comment.