Skip to content

Commit

Permalink
curation: process new created 30 days ago
Browse files Browse the repository at this point in the history
  • Loading branch information
yashlamba committed Jan 6, 2025
1 parent 554c881 commit e4df381
Showing 1 changed file with 52 additions and 25 deletions.
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

0 comments on commit e4df381

Please sign in to comment.