""" ETL Cable Command Line Interface. All required methods to setup and execute the command line for cable related tasks are in here. """ from datetime import date from datetime import timedelta from time import sleep from garcon.activity import ActivityWorker from garcon.decider import DeciderWorker from flows import config as base_config from flows import util from flows.cable_ingestion import config from flows.cable_ingestion import log from flows.cable_ingestion.flow import Flow def init_execute_parser(parser): """Setup the 'execute cable' sub-command to the cli. Args: parser (argparse.ArgumentParser): sub-command argument parser. """ parser.add_argument( '-s', '--start-date', dest='date_start', metavar='YYYY-MM-DD', type=util.date_cli_type, help=( 'Starting date of files to search for, inclusive. ' 'Default is 8 days ago.')) parser.add_argument( '-e', '--end-date', dest='date_end', metavar='YYYY-MM-DD', type=util.date_cli_type, help=( 'Ending date of files to search for, exclusive. ' "Default is tomorrow's date.")) def run_execute(correlation_id, date_end, date_start): """CLI entry point to the 'execute cable' sub-command. Args: correlation_id (str): new correlation ID for this ETL. date_end (date): ending date context. date_start (date): starting date context. Returns: str: workflow execution's run ID. """ context = {} context['correlation_id'] = correlation_id context['date_end'] = date_end if date_end else \ (date.today() + timedelta(days=1)).strftime('%Y-%m-%d') context['date_start'] = date_start if date_start else \ (date.today() - timedelta(days=8)).strftime('%Y-%m-%d') log.create(**context) context['correlation_id'] += '.1' resp = util.start_swf_execution( context, config.SWF_WORKFLOW_TIMEOUT, config.SWF_WORKFLOW_NAME, config.SWF_WORKFLOW_VERSION) log.add_run_id(correlation_id, resp['runId']) return resp['runId'] def init_worker_parser(parser): """Setup the 'worker cable_ingestion' sub-command to the cli. Args: parser (argparse.ArgumentParser): sub-command argument parser. """ pass def run_worker(): """CLI entry point to the 'worker cable_ingestion' sub-command.""" worker = ActivityWorker(Flow( base_config.SWF_DOMAIN, config.SWF_WORKFLOW_NAME, config.SWF_WORKFLOW_VERSION)) worker.run() def init_decider_parser(parser): """Setup the 'decider cable_ingestion' sub-command to the cli. Args: parser (argparse.ArgumentParser): sub-command argument parser. """ pass def run_decider(): """CLI entry point to the 'decider cable_ingestion' sub-command.""" decider = DeciderWorker(Flow( base_config.SWF_DOMAIN, config.SWF_WORKFLOW_NAME, config.SWF_WORKFLOW_VERSION)) while True: decider.run() sleep(1)