def init(): configs_factory.override( providers.Singleton(lambda: krules_settings) ) proc_events_rx_factory.override( providers.Singleton(rx.subjects.ReplaySubject) ) event_router_factory.override( providers.Singleton(lambda: EventRouter()) ) exceptions_dumpers = exceptions_dumpers_factory() exceptions_dumpers.set(ExceptionDumperBase) exceptions_dumpers.set(RequestsHTTPErrorDumper) # TODO: do it better source = None if "K_SERVICE" in os.environ: source = os.environ["K_SERVICE"] elif "SERVICE" in os.environ: source = os.environ["SERVICE"] else: source = socket.gethostname() from krules_cloudevents.route.dispatcher import CloudEventsDispatcher event_dispatcher_factory.override( providers.Singleton(lambda: CloudEventsDispatcher(krules_settings["CLOUDEVENTS"]["send_to"], source)) )
def init(): configs_factory.override(providers.Singleton(lambda: krules_settings)) proc_events_rx_factory.queue.clear() event_router_factory.override(providers.Singleton(lambda: EventRouter())) exceptions_dumpers = exceptions_dumpers_factory() exceptions_dumpers.set(ExceptionDumperBase) exceptions_dumpers.set(RequestsHTTPErrorDumper) # TODO: do it better source = None if "K_SERVICE" in os.environ: source = os.environ["K_SERVICE"] elif "SERVICE" in os.environ: source = os.environ["SERVICE"] else: source = socket.gethostname() from krules_cloudevents.route.dispatcher import CloudEventsDispatcher event_dispatcher_factory.override( providers.Singleton( lambda: CloudEventsDispatcher(_get_dispatch_url, source))) try: import env if "init" in dir(env) and callable(env.init): env.init() except ModuleNotFoundError: logger.warning("No application env.py found!") try: m_rules = importlib.import_module("ruleset") load_rules_from_rulesdata(m_rules.rulesdata) except ModuleNotFoundError as ex: if ex.name == "ruleset": logger.warning("No rules defined!") else: raise ex proc_events_filters = os.environ.get("PUBLISH_PROCEVENTS_MATCHING") if proc_events_filters: proc_events_rx_factory.subscribe( on_next=lambda x: publish_proc_events_filtered( x, proc_events_filters.split(";"), lambda match: match is not None)) else: proc_events_rx_factory.subscribe( on_next=lambda x: publish_proc_events_all(x))
from dependency_injector import providers from krules_core.providers import (configs_factory, event_router_factory, event_dispatcher_factory, subject_storage_factory, subject_factory) from krules_core.route.router import EventRouter from .route.dispatcher import CloudEventsDispatcher from krules_core.tests.subject.sqlite_storage import SQLLiteSubjectStorage from pytest_localserver.http import WSGIServer from werkzeug.wrappers import Request httpserver = plugin.httpserver configs_factory.override(providers.Singleton(lambda: {})) event_router_factory.override(providers.Singleton(EventRouter)) subject_storage_factory.override( providers.Factory( lambda x, **kwargs: SQLLiteSubjectStorage(x, ":memory:"))) def fake_receiver_app(environ, start_response): """Simplest possible WSGI application""" request = Request(environ) m = marshaller.NewDefaultHTTPMarshaller() event = m.FromRequest(v1.Event(), request.headers, io.BytesIO(request.data), lambda x: json.load(x)) event_info = event.Properties() event_info.update(event_info.pop("extensions")) subject = subject_factory(event_info.get("subject", "sys-0"))
def setup_module(_): from dependency_injector import providers as providers from krules_core.providers import event_router_factory event_router_factory.override(providers.Singleton(Router))