"""This is a small script that will run the main program on a schedule.""" # imports import logging import time from bulk_asset_scheduler import main as bulk_asset_scheduler from connectors.snowflake import close_connection import config # create logger with 'spam_application' logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) # create console handler with a higher log level ch = logging.StreamHandler() ch.setLevel(logging.INFO) # create formatter and add it to the handlers formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') # noqa ch.setFormatter(formatter) # add the handlers to the logger logger.addHandler(ch) # Constants FREQUENCY_IN_SECONDS = 600 MAX_RUNS = 1000 RUN_FOREVER = False MAX_CONCURRENT_SFN = 15 # Overwrite environment variables with constants config.MAX_CONCURRENT_SFN = MAX_CONCURRENT_SFN config.INPUT_TABLE_NAME = None # Run the main program in a loop run_count = 0 while True: run_count += 1 if not RUN_FOREVER: logger.info( f'Running bulk_asset_scheduler: attempt {run_count} of {MAX_RUNS}') else: logger.info( f'Running bulk_asset_scheduler: attempt {run_count}') bulk_asset_scheduler() logger.info( f'Waiting {FREQUENCY_IN_SECONDS} seconds before running again.') time.sleep(FREQUENCY_IN_SECONDS) if run_count == MAX_RUNS and not RUN_FOREVER: logger.info('Reached max runs. Exiting.') break logger.info('Closing Snowflake connection.') close_connection()