Skip to content

Commit

Permalink
datastreams: funders celery task using ror-http (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptamarit authored and jrcastro2 committed Jul 11, 2024
1 parent 206788e commit edef5a1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions invenio_vocabularies/services/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from flask import current_app

from ..datastreams.factories import DataStreamFactory
from ..factories import get_vocabulary_config


@shared_task(ignore_result=True)
Expand All @@ -26,3 +27,32 @@ def process_datastream(config):
if result.errors:
for err in result.errors:
current_app.logger.error(err)


@shared_task()
def import_funders():
"""Import the funders vocabulary.
Only new records are imported.
Existing records are not updated.
"""
vc = get_vocabulary_config("funders")
config = vc.get_config()

# When importing funders via a Celery task, make sure that we are automatically downloading the ROR file,
# instead of relying on a local file on the file system.
if config["readers"][0]["type"] == "ror-http":
readers_config_with_ror_http = config["readers"]
else:
readers_config_with_ror_http = [{"type": "ror-http"}] + config["readers"]

ds = DataStreamFactory.create(
readers_config=readers_config_with_ror_http,
transformers_config=config.get("transformers"),
writers_config=config["writers"],
)

for result in ds.process():
if result.errors:
for err in result.errors:
current_app.logger.error(err)
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ invenio_assets.webpack =
invenio_vocabularies = invenio_vocabularies.webpack:theme
invenio_i18n.translations =
invenio_vocabularies = invenio_vocabularies
invenio_celery.tasks =
invenio_vocabularies_services = invenio_vocabularies.services.tasks


[build_sphinx]
Expand Down

0 comments on commit edef5a1

Please sign in to comment.