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

curation: tasks: send results in email #1110

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
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)
slint marked this conversation as resolved.
Show resolved Hide resolved
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