"""Python daemon boilerplate.""" import sys from switchboard_consumer import config from switchboard_consumer.connectors import log_central from switchboard_consumer.connectors.msk import get_kafka_config from switchboard_consumer.connectors.graphql_product import \ get_gql_product_client from switchboard_consumer.connectors.sentry import sentry_client from switchboard_consumer.connectors.switchboard_aws import \ get_switchboard_credentials from switchboard_consumer.connectors.switchboard_graphql import \ get_swb_client from switchboard_consumer.logic.kafka import KafkaWorker if __name__ == '__main__': current_app_logger = log_central.get_current_logger() try: if config.KAFKA_BOOTSTRAP_BROKERS: kafka_configuration = { 'bootstrap_servers': config.KAFKA_BOOTSTRAP_BROKERS } else: if config.KAFKA_IS_LOCAL: credentials = {} else: credentials = get_switchboard_credentials() kafka_configuration = get_kafka_config( config.KAFKA_ARN, credentials, ) switchboard_client = get_swb_client() orchard_client = get_gql_product_client() current_app_logger.info('Starting application') kafka_worker = KafkaWorker(kafka_configuration) kafka_worker.run(switchboard_client, orchard_client) except Exception as err: if sentry_client: sentry_client.captureException() current_app_logger.critical('Error in application') current_app_logger.exception(err) sys.exit(1)