def _load_module(self, modname: str, prefix: Optional[str] = None): try: module = importlib.import_module(modname) except Exception as e: print('Unhandled exception while importing module {}: {}'.format( modname, str(e))) return prefix = modname + '.' if prefix is None else prefix self.procedures.update( **{ prefix + name: obj for name, obj in inspect.getmembers(module) if is_functional_procedure(obj) }) self.event_hooks.update( **{ prefix + name: obj for name, obj in inspect.getmembers(module) if is_functional_hook(obj) }) self.cronjobs.update( **{ prefix + name: obj for name, obj in inspect.getmembers(module) if is_functional_cron(obj) })
def _execute_procedure(self, *args, **kwargs): from platypush.config import Config from platypush.procedure import Procedure logger.info('Executing procedure request: {}'.format(self.action)) procedures = Config.get_procedures() proc_name = '.'.join(self.action.split('.')[1:]) if proc_name not in procedures: proc_name = self.action.split('.')[-1] proc_config = procedures[proc_name] if is_functional_procedure(proc_config): kwargs.update(**self.args) if 'n_tries' in kwargs: del kwargs['n_tries'] return proc_config(*args, **kwargs) proc = Procedure.build(name=proc_name, requests=proc_config['actions'], _async=proc_config['_async'], args=self.args, backend=self.backend, id=self.id) return proc.execute(*args, **kwargs)