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: process new records created 30 days ago #1111

Merged
merged 1 commit into from
Jan 16, 2025
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
77 changes: 52 additions & 25 deletions site/zenodo_rdm/curation/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

def _send_result_email(content):
"""Send curation result as email."""
subject = f"EU Record Curation Processesed {datetime.now().date()}"
subject = f"EU Record Curation Processed {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"]
Expand All @@ -44,36 +44,21 @@ def _send_result_email(content):
mail_ext.send(msg)


@shared_task
def run_eu_record_curation(since):
"""Run EC Curator."""
ctx = {
"processed": 0,
"approved": 0,
"failed": 0,
"since": since,
"records_moved": [],
}
dry_run = not current_app.config.get("CURATION_ENABLE_EU_CURATOR")
curator = EURecordCurator(dry=dry_run)
created_before = (datetime.now(timezone.utc) - timedelta(days=30)).isoformat()
updated_after = (datetime.fromisoformat(since) - timedelta(hours=12)).isoformat()
def _get_eu_records_query(since):
"""Get dsl query for records to be processed."""
created_before = datetime.now(timezone.utc) - timedelta(days=30)
updated_after = datetime.fromisoformat(since) - timedelta(hours=12)

query = dsl.Q(
# Get records with EC funding and not in EU community already and not created in last 30 days
ec_funded = dsl.Q(
"bool",
must=[
dsl.Q("term", **{"metadata.funding.funder.id": "00k4n6c32"}),
dsl.Q("term", **{"is_deleted": False}),
dsl.Q(
"range",
created={
"lte": created_before,
},
),
dsl.Q(
"range",
updated={
"gte": updated_after,
"lte": created_before.isoformat(),
},
),
],
Expand All @@ -85,14 +70,56 @@ def run_eu_record_curation(since):
"EU_COMMUNITY_UUID"
)
},
)
),
],
)

updated_after_since = dsl.Q(
"bool",
must=[
dsl.Q(
"range",
updated={
"gte": updated_after.isoformat(),
},
),
],
)

# Created 31 days before (with a 6 hour buffer)
new_created = dsl.Q(
"bool",
must=[
dsl.Q(
"range",
created={
"gte": (created_before - timedelta(days=1, hours=6)).isoformat(),
},
),
],
)

return ec_funded & (updated_after_since | new_created)


@shared_task
def run_eu_record_curation(since):
"""Run EC Curator."""
ctx = {
"processed": 0,
"approved": 0,
"failed": 0,
"since": since,
"records_moved": [],
}
dry_run = not current_app.config.get("CURATION_ENABLE_EU_CURATOR")
curator = EURecordCurator(dry=dry_run)

search = records_service.create_search(
system_identity,
records_service.record_cls,
records_service.config.search,
extra_filter=query,
extra_filter=_get_eu_records_query(since),
)

for item in search.scan():
Expand Down