""" ETL Distribution Fee Command Line Interface. All required methods to setup and execute the command line for distribution_fee related tasks are in here. """ 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.distribution_fee import config from flows.distribution_fee import log from flows.distribution_fee.flow import Flow from flows.flow import DatabaseParam def init_execute_parser(parser): """Setup the 'execute distribution_fee' sub-command to the cli. Args: parser (argparse.ArgumentParser): sub-command argument parser. """ parser.add_argument( '-u', '--upc', action='append', dest='upcs', metavar='UPC', type=util.upc_cli_type, help='Release UPC(s) to process. This can be used multiple times.') def run_execute(correlation_id, upcs): """CLI entry point to the 'execute distribution_fee' sub-command. Args: correlation_id (str): new correlation ID for this ETL. upcs (tuple): UPCs to process. Returns: str: workflow execution's run ID. """ context = {} context['correlation_id'] = correlation_id upcs = tuple(upcs) if upcs else util.get_serviced_upcs(True) context['upcs'] = DatabaseParam('upcs', data=upcs) 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, config.SWF_WORKFLOW_ID) log.add_run_id(correlation_id, resp['runId']) return resp['runId'] def init_worker_parser(parser): """Setup the 'worker distribution_fee' sub-command to the cli. Args: parser (argparse.ArgumentParser): sub-command argument parser. """ pass def run_worker(): """CLI entry point to the 'worker distribution_fee' 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 distribution_fee' sub-command to the cli. Args: parser (argparse.ArgumentParser): sub-command argument parser. """ pass def run_decider(): """CLI entry point to the 'decider distribution_fee' sub-command.""" decider = DeciderWorker(Flow( base_config.SWF_DOMAIN, config.SWF_WORKFLOW_NAME, config.SWF_WORKFLOW_VERSION)) while True: decider.run() sleep(1)