def run_scheduler_task(task_name, stack_name): configuration = TaskConfiguration() task_item = configuration.get_config_item(task_name) if task_item is None: raise ValueError( "Task \"{}\" is not configured in stack \"{}\"".format( task_name, stack_name)) print_verbose("Configuration item is\n{}", safe_json(task_item, indent=3)) task = TaskConfiguration( context=used_context, logger=ConsoleLogger()).configuration_item_to_task(task_item) event = { handlers.HANDLER_EVENT_ACTION: handlers.HANDLER_ACTION_SELECT_RESOURCES, handlers.HANDLER_EVENT_TASK: task, handlers.HANDLER_EVENT_SOURCE: sys.argv[0], handlers.HANDLER_EVENT_TASK_DT: datetime.now().isoformat() } for sub_task in ScheduleHandler.task_account_region_sub_tasks(task): event[handlers.HANDLER_EVENT_SUB_TASK] = sub_task print_verbose("Event is \n{}", safe_json(event, indent=3)) handler = handlers.create_handler("SelectResourcesHandler", event, used_context) result = handler.handle_request() print_verbose("(Sub) Task result is\n{}", safe_json(result, indent=3))
def lambda_handler(event, context): dt = datetime.utcnow() log_stream_name = LOG_STREAM.format("OpsAutomatorMain", dt.year, dt.month, dt.day) with outputs.queued_logger.QueuedLogger(logstream=log_stream_name, context=context, buffersize=20) as logger: for handler_name in handlers.all_handlers(): try: if not handlers.get_class_for_handler(handler_name).is_handling_request(event, context): continue except Exception as ex: logger.error(ERR_IS_HANDLING, handler_name, safe_json(event, indent=2), ex) break if context is not None and os.getenv(ENV_DEBUG_MAIN_EVENT_HANDLER, "false").lower() == "true": print("Handler is {}".format(handler_name)) print("Event is {}".format(safe_json(event, indent=3))) handler = handlers.create_handler(handler_name, event, context) try: logger.debug(DEBUG_HANDLER_INFO, handler_name) result = handler.handle_request() return safe_dict(result) except Exception as e: logger.error(ERR_HANDLING_REQUEST, safe_json(event, indent=2), handler_name, e, full_stack()) finally: if len(boto_retry.statistics) > 0: logger.info(MSG_BOTO_STATS, safe_json(boto_retry.statistics, indent=3)) boto_retry.clear_statistics() return else: logger.debug(MSG_NO_REQUEST_HANDLER, safe_json(event, indent=2))
def lambda_handler(event, context): dt = datetime.utcnow() logstream = LOG_STREAM.format("OpsAutomatorMain", dt.year, dt.month, dt.day) with Logger(logstream=logstream, context=context, buffersize=20) as logger: logger.info("Ops Automator, version %version%") for handler_name in handlers.all_handlers(): if handlers.get_class_for_handler(handler_name).is_handling_request(event): handler = handlers.create_handler(handler_name, event, context) logger.info("Handler is {}", handler_name) try: result = handler.handle_request() logger.info(MSG_REQUEST_HANLED, handler_name, (datetime.utcnow() - dt).total_seconds()) return safe_dict(result) except Exception as e: logger.error(MSG_ERR_HANDLING_REQUEST, safe_json(event, indent=2), handler_name, e, traceback.format_exc()) return logger.error(MSG_NO_REQUEST_HANDLER, safe_json(event, indent=2))
def create_waiverdb_handler(greenwave_server): return handlers.create_handler(waiverdb.WaiverDBHandler, 'topic_prefix.environment.waiver.new', greenwave_server)
def create_resultdb_handler(greenwave_server, cache_config=None): return handlers.create_handler( resultsdb.ResultsDBHandler, 'topic_prefix.environment.taskotron.result.new', greenwave_server, cache_config)