Example #1
0
 def get_handler(self) -> Callable:
     # Use this function to avoid circular dependency accessing Petisco objects before its configuration
     handler = (get_function_from_string(self.handler_key).handle(
         on_failure=raise_petisco_config_exception,
         failure_args=(self.kdict, "tasks:*:handler"),
     ).unwrap())
     return handler
    def from_dict(kdict):

        provider = kdict.get("provider")
        if not provider:
            raise TypeError(
                f"ConfigEventsSubscriber: {provider} is a required parameter")
        provider = (get_function_from_string(provider).handle(
            on_failure=raise_petisco_config_exception,
            failure_args=(kdict, "event:subscriber:provider"),
        ).unwrap())

        subscribers = {}
        subscribers_dict = kdict.get("subscribers")
        if subscribers_dict:
            if not isinstance(subscribers_dict, dict):
                raise TypeError(
                    f"ConfigEventManager: subscribers must be a Dict with information about event subscribers"
                )
            subscribers = {
                k: ConfigEventSubscriber.from_dict(v)
                for k, v in subscribers_dict.items()
            }

        return ConfigEventsSubscriber(provider=provider,
                                      subscribers=subscribers)
Example #3
0
def get_handlers(handlers_names: List[str], kdict: Dict) -> List[Callable]:
    handlers = []
    for handler_name in handlers_names:
        handler = (get_function_from_string(handler_name).handle(
            on_failure=raise_petisco_config_exception,
            failure_args=kdict).unwrap())
        handlers.append(handler)
    return handlers
    def from_dict(kdict):
        provider = get_default_notifier
        if kdict and isinstance(kdict, dict):
            provider = (get_function_from_string(kdict.get("provider")).handle(
                on_failure=raise_petisco_config_exception,
                failure_args=(kdict, "notifier:provider"),
            ).unwrap())

        return ConfigNotifier(provider=provider)
    def get_handler(self):
        # Use this function to avoid circular dependency accessing Petisco objects before its configuration

        if self.handler_key:
            handler = (get_function_from_string(self.handler_key).handle(
                on_failure=raise_petisco_config_exception,
                failure_args=(self.kdict, "event:subscriber:subscriber"),
            ).unwrap())
        else:
            handler = self.handler

        return handler
 def from_dict(kdict):
     if not kdict or not isinstance(kdict, List):
         return ConfigPersistence()
     configs = {}
     for entry in kdict:
         config = (get_function_from_string(entry.get("config")).handle(
             on_failure=raise_petisco_config_exception,
             failure_args=(entry, "persistence:config"),
         ).unwrap())
         configs[entry["name"]] = SingleConfigPersistence(
             type=entry["type"], config=config, models=entry.get("models"))
     return ConfigPersistence(configs=configs)
    def from_dict(kdict):
        config = (get_function_from_string(kdict.get("config")).handle(
            on_failure=raise_petisco_config_exception,
            failure_args=kdict).unwrap())

        return ConfigLogger(
            selected_logger=kdict.get("selected_logger",
                                      "not_implemented_logger"),
            name=kdict.get("name"),
            format=kdict.get("format",
                             "%(name)s - %(levelname)s - %(message)s"),
            config=config,
        )
    def from_dict(kdict):
        config_dependencies = (get_function_from_string(
            kdict.get("config_dependencies")).handle(
                on_failure=raise_petisco_config_exception,
                failure_args=(kdict, "providers:config_dependencies"),
            ).unwrap())
        services_provider = (get_function_from_string(
            kdict.get("services_provider")).handle(
                on_failure=raise_petisco_config_exception,
                failure_args=(kdict, "providers:services_provider"),
            ).unwrap())
        repositories_provider = (get_function_from_string(
            kdict.get("repositories_provider")).handle(
                on_failure=raise_petisco_config_exception,
                failure_args=(kdict, "providers:repositories_provider"),
            ).unwrap())

        return ConfigProviders(
            config_dependencies=config_dependencies,
            services_provider=services_provider,
            repositories_provider=repositories_provider,
        )