def run_mailer_in_parallel(mailer_config, aws_session, logger, max_num_processes): max_num_processes = int(max_num_processes) if max_num_processes < 1: raise Exception sqs_queue_processor = MailerSqsQueueProcessor(mailer_config, aws_session, logger) sqs_queue_processor.max_num_processes = max_num_processes sqs_queue_processor.run(parallel=True)
def run_c7n_mailer(logger): email_config_filepath = '/custodian/email/email-config.yml' email_config = yaml.load(get_file_contents(email_config_filepath), Loader=yaml.SafeLoader) session = boto3.Session() mailer_sqs_queue_processor = MailerSqsQueueProcessor( email_config, session, logger) mailer_sqs_queue_processor.run(parallel=False)
def run_mailer_in_parallel(mailer_config, aws_session, logger, max_num_processes): try: max_num_processes = int(max_num_processes) if max_num_processes < 1: raise Exception except: print('--max-num-processes must be an integer') return sqs_queue_processor = MailerSqsQueueProcessor(mailer_config, aws_session, logger) sqs_queue_processor.max_num_processes = max_num_processes sqs_queue_processor.run(parallel=True)
def run_mailer_in_parallel(mailer_config, aws_session, logger, max_num_processes): try: max_num_processes = int(max_num_processes) if max_num_processes < 1: raise Exception except: print('--max-num-processes must be an integer') return sqs_queue_processor = MailerSqsQueueProcessor(mailer_config, aws_session, logger) sqs_queue_processor.max_num_processes = max_num_processes sqs_queue_processor.run(parallel=True)
def main(): parser = get_c7n_mailer_parser() args = parser.parse_args() mailer_config = get_and_validate_mailer_config(args) args_dict = vars(args) logger = get_logger(debug=args_dict.get('debug', False)) if args_dict.get('update_lambda'): if is_azure_cloud(mailer_config): print('\n** Lambda support not available for Azure queues **\n') return if args_dict.get('debug'): print('\n** --debug is only supported with --run, not --update-lambda **\n') return if args_dict.get('max_num_processes'): print('\n** --max-num-processes is only supported ' 'with --run, not --update-lambda **\n') return deploy.provision(mailer_config, functools.partial(session_factory, mailer_config)) if args_dict.get('run'): max_num_processes = args_dict.get('max_num_processes') # Select correct processor if is_azure_cloud(mailer_config): processor = MailerAzureQueueProcessor(mailer_config, logger) else: aws_session = session_factory(mailer_config) processor = MailerSqsQueueProcessor(mailer_config, aws_session, logger) # Execute if max_num_processes: run_mailer_in_parallel(processor, max_num_processes) else: processor.run()
def main(): parser = get_c7n_mailer_parser() args = parser.parse_args() mailer_config = get_and_validate_mailer_config(args) aws_session = session_factory(mailer_config) args_dict = vars(args) logger = get_logger(debug=args_dict.get('debug', False)) if args_dict.get('update_lambda'): if args_dict.get('debug'): print( '\n** --debug is only supported with --run, not --update-lambda **\n' ) return if args_dict.get('max_num_processes'): print( '\n** --max-num-processes is only supported with --run, not --update-lambda **\n' ) return deploy.provision(mailer_config, functools.partial(session_factory, mailer_config)) if args_dict.get('run'): max_num_processes = args_dict.get('max_num_processes') if max_num_processes: run_mailer_in_parallel(mailer_config, aws_session, logger, max_num_processes) else: MailerSqsQueueProcessor(mailer_config, aws_session, logger).run()
def main(): parser = get_c7n_mailer_parser() args = parser.parse_args() mailer_config = get_and_validate_mailer_config(args) args_dict = vars(args) logger = get_logger(debug=args_dict.get('debug', False)) module_dir = path.dirname(path.abspath(__file__)) default_templates = [ path.abspath(path.join(module_dir, 'msg-templates')), path.abspath(path.join(module_dir, '..', 'msg-templates')), path.abspath('.') ] templates = args_dict.get('templates', None) if templates: default_templates.append( path.abspath(path.expanduser(path.expandvars(templates)))) mailer_config['templates_folders'] = default_templates provider = get_provider(mailer_config) if args_dict.get('update_lambda'): if args_dict.get('debug'): print( '\n** --debug is only supported with --run, not --update-lambda **\n' ) return if args_dict.get('max_num_processes'): print('\n** --max-num-processes is only supported ' 'with --run, not --update-lambda **\n') return if provider == Providers.Azure: azure_deploy.provision(mailer_config) elif provider == Providers.AWS: deploy.provision(mailer_config, functools.partial(session_factory, mailer_config)) if args_dict.get('run'): max_num_processes = args_dict.get('max_num_processes') # Select correct processor if provider == Providers.Azure: processor = MailerAzureQueueProcessor(mailer_config, logger) elif provider == Providers.AWS: aws_session = session_factory(mailer_config) processor = MailerSqsQueueProcessor(mailer_config, aws_session, logger) # Execute if max_num_processes: run_mailer_in_parallel(processor, max_num_processes) else: processor.run()