def wrapper(*args, **kwargs): """ An wrapper for cli functions. :param args: Positional argument. :param kwargs: A passthrough keyword argument """ if check_cli_args: _check_cli_args(args) metrics = _build_metrics(f.__name__, args, kwargs) cli_action_loggers.on_pre_execution(**metrics) try: # Check and run migrations if necessary if check_db: from airflow.utils.db import check_and_run_migrations, synchronize_log_template check_and_run_migrations() synchronize_log_template() return f(*args, **kwargs) except Exception as e: metrics['error'] = e raise finally: metrics['end_datetime'] = datetime.utcnow() cli_action_loggers.on_post_execution(**metrics)
def wrapper(*args, **kwargs): """ An wrapper for cli functions. It assumes to have Namespace instance at 1st positional argument :param args: Positional argument. It assumes to have Namespace instance at 1st positional argument :param kwargs: A passthrough keyword argument """ _check_cli_args(args) metrics = _build_metrics(f.__name__, args[0]) cli_action_loggers.on_pre_execution(**metrics) try: # Check and run migrations if necessary if check_db: check_and_run_migrations() synchronize_log_template() return f(*args, **kwargs) except Exception as e: metrics['error'] = e raise finally: metrics['end_datetime'] = datetime.utcnow() cli_action_loggers.on_post_execution(**metrics)