From a50458e8143aa2854ca2a9e4590518d7425d9e88 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Thu, 12 Dec 2024 16:51:46 +0100 Subject: [PATCH] allowing str or list as offline command --- src/scicat_configuration.py | 2 +- src/scicat_online_ingestor.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/scicat_configuration.py b/src/scicat_configuration.py index 5bba866..9ae9381 100644 --- a/src/scicat_configuration.py +++ b/src/scicat_configuration.py @@ -225,7 +225,7 @@ class FileHandlingOptions: @dataclass(kw_only=True) class IngestionOptions: dry_run: bool = False - offline_ingestor_executable: str = "background_ingestor" + offline_ingestor_executable: str | list[str]= "background_ingestor" schemas_directory: str = "schemas" check_if_dataset_exists_by_pid: bool = True check_if_dataset_exists_by_metadata: bool = True diff --git a/src/scicat_online_ingestor.py b/src/scicat_online_ingestor.py index b489d8c..c6ea099 100644 --- a/src/scicat_online_ingestor.py +++ b/src/scicat_online_ingestor.py @@ -37,11 +37,11 @@ def dump_message_to_file_if_needed( - *, - logger: logging.Logger, - message_file_path: pathlib.Path, - file_handling_options: FileHandlingOptions, - message: WritingFinished, + *, + logger: logging.Logger, + message_file_path: pathlib.Path, + file_handling_options: FileHandlingOptions, + message: WritingFinished, ) -> None: """Dump the message to a file according to the configuration.""" if not file_handling_options.message_to_file: @@ -93,6 +93,10 @@ def build_online_config(logger: logging.Logger | None = None) -> OnlineIngestorC ) +def _pre_executable_offline_ingestor(offline_ingestor: str | list[str]) -> list[str]: + return [offline_ingestor] if isinstance(offline_ingestor, str) else offline_ingestor + + def main() -> None: """Main entry point of the app.""" tmp_config = build_online_config() @@ -103,7 +107,7 @@ def main() -> None: logger.info('Starting the Scicat online Ingestor with the following configuration:') logger.info(config.to_dict()) - with handle_daemon_loop_exceptions(logger=logger): + with ((handle_daemon_loop_exceptions(logger=logger))): # Kafka consumer if (consumer := build_consumer(config.kafka, logger)) is None: raise RuntimeError("Failed to build the Kafka consumer") @@ -135,8 +139,7 @@ def main() -> None: --done-writing-message-file message_file_path # optional depending on the message_saving_options.message_output """ - cmd = [ - config.ingestion.offline_ingestor_executable, + cmd = _pre_executable_offline_ingestor(config.ingestion.offline_ingestor_executable) + [ "-c", config.config_file, "--nexus-file",