def run_enrichments()

in elkserver/docker/redelk-base/redelkinstalldata/scripts/daemon.py [0:0]


def run_enrichments(enrich_dict):
    """Run the different enrichment scripts that are enabled"""
    logger.info("Running enrichment modules")
    # First loop through the enrichment modules
    for enrich_module in enrich_dict:
        if module_should_run(enrich_module, "redelk_enrich"):
            try:
                logger.debug("[e] initiating class Module() in %s", enrich_module)
                module_class = enrich_dict[enrich_module]["m"].Module()
                logger.debug(
                    "[e] Running Run() from the Module class in %s", enrich_module
                )
                enrich_dict[enrich_module]["result"] = copy.deepcopy(module_class.run())

                # Now loop through the hits and tag them
                for hit in enrich_dict[enrich_module]["result"]["hits"]["hits"]:
                    set_tags(enrich_dict[enrich_module]["info"]["submodule"], [hit])

                hits = len(enrich_dict[enrich_module]["result"]["hits"]["hits"])
                module_did_run(
                    enrich_module,
                    "enrich",
                    "success",
                    f"Enriched {hits} documents",
                    hits,
                )
                enrich_dict[enrich_module]["status"] = "success"
            # pylint: disable=broad-except
            except Exception as error:
                stack_trace = traceback.format_exc()
                msg = f"Error running enrichment {enrich_module}: {error} | StackTrace: {stack_trace}"
                logger.error(msg)
                logger.exception(error)
                module_did_run(enrich_module, "enrich", "error", msg)
                enrich_dict[enrich_module]["status"] = "error"
        else:
            enrich_dict[enrich_module]["status"] = "did_not_run"
    return enrich_dict