def run() -> None: """Update path and run the App.""" # update the path to ensure the App has access to required modules app_lib = AppLib() app_lib.update_path() # import modules after path has been updated # third-party from tcex import TcEx # pylint: disable=import-outside-toplevel # first-party from app import App # pylint: disable=import-outside-toplevel tcex = TcEx() try: # load App class app = App(tcex) # perform prep/setup operations app.setup(**{}) # run the App logic if hasattr(app.args, 'tc_action') and app.args.tc_action is not None: # if the args NameSpace has the reserved arg of "tc_action", this arg value is used to # triggers a call to the app.<tc_action>() method. an exact match to the method is # tried first, followed by a normalization of the tc_action value, and finally an # attempt is made to find the reserved "tc_action_map" property to map value to method. tc_action: str = app.args.tc_action tc_action_formatted: str = tc_action.lower().replace(' ', '_') tc_action_map = 'tc_action_map' # reserved property name for action to method map # run action method if hasattr(app, tc_action): getattr(app, tc_action)() elif hasattr(app, tc_action_formatted): getattr(app, tc_action_formatted)() elif hasattr(app, tc_action_map): app.tc_action_map.get(app.args.tc_action)() # pylint: disable=no-member else: tcex.exit( 1, f'Action method ({app.args.tc_action}) was not found.') else: # default to run method app.run(**{}) # write requested value for downstream Apps app.write_output() # pylint: disable=no-member # perform cleanup/teardown operations app.teardown(**{}) # explicitly call the exit method tcex.playbook.exit(msg=app.exit_message) except Exception as e: main_err = f'Generic Error. See logs for more details ({e}).' tcex.log.error(traceback.format_exc()) tcex.playbook.exit(1, main_err)
def run() -> None: """Update path and run the App.""" # update the path to ensure the App has access to required modules app_lib = AppLib() app_lib.update_path() # import modules after path has been updated # third-party from app import App # pylint: disable=import-outside-toplevel from tcex import TcEx # pylint: disable=import-outside-toplevel tcex = TcEx() try: # load App class app = App(tcex) # perform prep/setup operations app.setup(**{}) # run the App logic app.run(**{}) # perform cleanup/teardown operations app.teardown(**{}) # explicitly call the exit method tcex.exit(msg=app.exit_message) except Exception as e: main_err = f'Generic Error. See logs for more details ({e}).' tcex.log.error(traceback.format_exc()) tcex.playbook.exit(1, main_err)
def run(**kwargs): """Update path and run the App.""" # update the path to ensure the App has access to required modules app_lib = AppLib() app_lib.update_path() # import modules after path has been updated from tcex import TcEx # pylint: disable=import-outside-toplevel from app import App # pylint: disable=import-outside-toplevel tcex = TcEx() try: # load App class app = App(tcex) # set app property in testing framework if callable(kwargs.get('set_app')): kwargs.get('set_app')(app) # configure custom trigger message handler tcex.service.create_config_callback = app.create_config_callback tcex.service.delete_config_callback = app.delete_config_callback tcex.service.shutdown_callback = app.shutdown_callback tcex.service.webhook_event_callback = app.webhook_event_callback # perform prep/setup operations app.setup() # listen on channel/topic tcex.service.listen() # start heartbeat threads tcex.service.heartbeat() # inform TC that micro-service is Ready tcex.service.ready = True # loop until exit if hasattr(app, 'loop_forever'): app.loop_forever() # pylint: disable=no-member else: tcex.log.info('Looping until shutdown') while tcex.service.loop_forever(sleep=1): pass # perform cleanup/teardown operations app.teardown() # explicitly call the exit method tcex.playbook.exit(msg=app.exit_message) except Exception as e: main_err = f'Generic Error. See logs for more details ({e}).' tcex.log.error(traceback.format_exc()) tcex.playbook.exit(1, main_err)
def run() -> None: """Update path and run the App.""" # update the path to ensure the App has access to required modules app_lib = AppLib() app_lib.update_path() # import modules after path has been updated # third-party from tcex import TcEx # pylint: disable=import-outside-toplevel # first-party from app import App # pylint: disable=import-outside-toplevel config_file = 'app_config.json' if not os.path.isfile(config_file): print(f'Missing {config_file} config file.') tcex = TcEx(config_file=config_file) try: # load App class app = App(tcex) # perform prep/setup operations app.setup() # run the App logic app.run() # pylint: disable=no-member # perform cleanup/teardown operations app.teardown() # explicitly call the exit method tcex.exit(msg=app.exit_message) except Exception as e: main_err = f'Generic Error. See logs for more details ({e}).' tcex.log.error(traceback.format_exc()) tcex.exit(1, main_err)
# -*- coding: utf-8 -*- """Playbook App""" import traceback from app_lib import AppLib # pylint: disable=no-member if __name__ == '__main__': # update the path to ensure the App has access to required modules app_lib = AppLib() app_lib.update_path() # import modules after path has been updated from tcex import TcEx from app import App tcex = TcEx() try: # load App class app = App(tcex) # configure custom trigger message handler tcex.service.create_config_callback = app.create_config_callback tcex.service.delete_config_callback = app.delete_config_callback tcex.service.shutdown_callback = app.shutdown_callback # perform prep/setup operations app.setup()