-
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.
datastreams: implement asynchronous writer
- Loading branch information
Showing
5 changed files
with
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2022 CERN. | ||
# | ||
# Invenio-Vocabularies is free software; you can redistribute it and/or | ||
# modify it under the terms of the MIT License; see LICENSE file for more | ||
# details. | ||
|
||
"""Data Streams Celery tasks.""" | ||
|
||
from celery import shared_task | ||
|
||
from ..datastreams import StreamEntry | ||
from ..datastreams.factories import WriterFactory | ||
|
||
|
||
@shared_task(ignore_result=True) | ||
def write_entry(writer, entry): | ||
"""Write an entry. | ||
:param writer: writer configuration as accepted by the WriterFactory. | ||
:param entry: dictionary, StreamEntry is not serializable. | ||
""" | ||
writer = WriterFactory.create(config=writer) | ||
writer.write(StreamEntry(entry)) |
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
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,34 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2021-2022 CERN. | ||
# | ||
# Invenio-Vocabularies is free software; you can redistribute it and/or | ||
# modify it under the terms of the MIT License; see LICENSE file for more | ||
# details. | ||
|
||
"""Data Streams tasks tests.""" | ||
|
||
from pathlib import Path | ||
|
||
import yaml | ||
|
||
from invenio_vocabularies.datastreams import StreamEntry | ||
from invenio_vocabularies.datastreams.tasks import write_entry | ||
|
||
|
||
def test_write_entry(app): | ||
filepath = 'writer_test.yaml' | ||
yaml_writer_config = { | ||
"type": "yaml", | ||
"args": { | ||
"filepath": filepath | ||
} | ||
} | ||
entry = {"key_one": [{"inner_one": 1}]} | ||
write_entry(yaml_writer_config, entry) | ||
|
||
filepath = Path(filepath) | ||
with open(filepath) as file: | ||
assert yaml.safe_load(file) == [entry] | ||
|
||
filepath.unlink() |
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