def run_from_args(parsed): task = None cfg = None if parsed.which == 'init': # bypass looking for a project file if we're running `dbt init` task = parsed.cls(args=parsed) else: nearest_project_dir = get_nearest_project_dir() if nearest_project_dir is None: raise RuntimeError( "fatal: Not a dbt project (or any of the parent directories). " "Missing dbt_project.yml file") os.chdir(nearest_project_dir) res = invoke_dbt(parsed) if res is None: raise RuntimeError("Could not run dbt") else: task, cfg = res log_path = None if cfg is not None: log_path = cfg.log_path initialize_logger(parsed.debug, log_path) logger.debug("Tracking: {}".format(dbt.tracking.active_user.state())) dbt.tracking.track_invocation_start(config=cfg, args=parsed) results = run_from_task(task, cfg, parsed) return task, results
def run_from_args(parsed): task = None proj = None if parsed.which == 'init': # bypass looking for a project file if we're running `dbt init` task = parsed.cls(args=parsed) else: nearest_project_dir = get_nearest_project_dir() if nearest_project_dir is None: raise RuntimeError( "fatal: Not a dbt project (or any of the parent directories). " "Missing dbt_project.yml file") os.chdir(nearest_project_dir) res = invoke_dbt(parsed) if res is None: raise RuntimeError("Could not run dbt") else: task, proj = res log_path = None if proj is not None: log_path = proj.get('log-path', 'logs') initialize_logger(parsed.debug, log_path) logger.debug("Tracking: {}".format(dbt.tracking.active_user.state())) dbt.tracking.track_invocation_start(project=proj, args=parsed) result = None try: result = task.run() dbt.tracking.track_invocation_end(project=proj, args=parsed, result_type="ok", result=None) except (dbt.exceptions.NotImplementedException, dbt.exceptions.FailedToConnectException) as e: logger.info('ERROR: {}'.format(e)) dbt.tracking.track_invocation_end(project=proj, args=parsed, result_type="error", result=str(e)) except Exception as e: dbt.tracking.track_invocation_end(project=proj, args=parsed, result_type="error", result=str(e)) raise return result
def run_from_args(parsed): task = None proj = None if parsed.which == 'init': # bypass looking for a project file if we're running `dbt init` task = parsed.cls(args=parsed) else: nearest_project_dir = get_nearest_project_dir() if nearest_project_dir is None: raise RuntimeError( "fatal: Not a dbt project (or any of the parent directories). " "Missing dbt_project.yml file") os.chdir(nearest_project_dir) res = invoke_dbt(parsed) if res is None: raise RuntimeError("Could not run dbt") else: task, proj = res log_path = None if proj is not None: log_path = proj.get('log-path', 'logs') initialize_logger(parsed.debug, log_path) dbt.tracking.track_invocation_start(project=proj, args=parsed) try: return task.run() dbt.tracking.track_invocation_end(project=proj, args=parsed, result_type="ok", result=None) except Exception as e: dbt.tracking.track_invocation_end(project=proj, args=parsed, result_type="error", result=str(e)) raise
def run_from_args(parsed): log_cache_events(getattr(parsed, 'log_cache_events', False)) flags.set_from_args(parsed) parsed.cls.pre_init_hook() logger.info("Running with dbt{}".format(dbt.version.installed)) # this will convert DbtConfigErrors into RuntimeExceptions task = parsed.cls.from_args(args=parsed) logger.debug("running dbt with arguments %s", parsed) log_path = None if task.config is not None: log_path = getattr(task.config, 'log_path', None) initialize_logger(parsed.debug, log_path) logger.debug("Tracking: {}".format(dbt.tracking.active_user.state())) results = None with track_run(task): results = task.run() return task, results