-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import datetime | ||
import typing | ||
|
||
from invenio_jobs.jobs import RegisteredTask | ||
|
||
from invenio_vocabularies.services.tasks import process_datastream | ||
from marshmallow import EXCLUDE, Schema, fields, validate, post_load, types | ||
from marshmallow_utils.fields import SanitizedUnicode, TZDateTime | ||
from datetime import timezone | ||
|
||
|
||
class ArgsSchema(Schema): | ||
|
||
since = TZDateTime( | ||
timezone=timezone.utc, | ||
format="iso", | ||
metadata={ | ||
"description": "YYYY-MM-DD HH:mm format. Leave field empty if it should continue since last successful run" | ||
}, | ||
) | ||
type = fields.String( | ||
metadata={"type": "hidden"}, | ||
dump_default="ArgsSchemaAPI", | ||
load_default="ArgsSchemaAPI", | ||
) | ||
|
||
|
||
class ProcessDataStreamRegisteredTask(RegisteredTask): | ||
|
||
arguments_schema = ArgsSchema | ||
task = process_datastream | ||
id = "process_datastream" | ||
title = "Generic Process Data Stream task" | ||
|
||
@classmethod | ||
def build_task_arguments(cls, job_obj, since=None, custom_args=None, **kwargs): | ||
raise NotImplemented | ||
|
||
|
||
class ProcessRORAffiliationsRegisteredTask(ProcessDataStreamRegisteredTask): | ||
"""Process ROR affiliations datastream registered task.""" | ||
|
||
description = "Process ROR affiliations" | ||
title = "Load ROR affiliations" | ||
|
||
@classmethod | ||
def build_task_arguments(cls, job_obj, since=None, custom_args=None, **kwargs): | ||
if custom_args: | ||
return custom_args | ||
|
||
if since is None and job_obj.last_runs["success"]: | ||
since = job_obj.last_runs["success"].started_at | ||
else: | ||
since = datetime.datetime.now() | ||
|
||
return {"config": { | ||
"readers": [ | ||
{ | ||
"args": {"since": since}, | ||
"type": "ror-http", | ||
}, | ||
{"args": {"regex": "_schema_v2\\.json$"}, "type": "zip"}, | ||
{"type": "json"}, | ||
], | ||
"writers": [ | ||
{ | ||
"args": { | ||
"writer": { | ||
"type": "affiliations-service", | ||
"args": {"update": True}, | ||
} | ||
}, | ||
"type": "async", | ||
} | ||
], | ||
"transformers": [{"type": "ror-affiliations"}], | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters