-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors dbt-running functionality into a function, updates taskflow…
…s, and addresses the dataset change that highlighted the issue.
- Loading branch information
1 parent
cecfb52
commit ff2e9e6
Showing
6 changed files
with
156 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from logging import Logger | ||
import subprocess | ||
import re | ||
|
||
from cc_utils.utils import log_as_info | ||
|
||
|
||
class DbtExecutionError(Exception): | ||
def __init__(self, msg): | ||
super().__init__(msg) | ||
|
||
|
||
def run_dbt_dataset_transformations( | ||
dataset_name: str, task_logger: Logger, schema: str = "data_raw", dbt_project: str = "re_dbt" | ||
) -> bool: | ||
dbt_cmd = f"""cd /opt/airflow/dbt && \ | ||
dbt --warn-error-options \ | ||
'{{"include": "all", "exclude": [UnusedResourceConfigPath]}}' \ | ||
run --select {dbt_project}.{schema}.{dataset_name}""" | ||
log_as_info(task_logger, f"dbt run command: {dbt_cmd}") | ||
subproc_output = subprocess.run(dbt_cmd, shell=True, capture_output=True, text=True) | ||
raise_exception = False | ||
for el in subproc_output.stdout.split("\n"): | ||
log_as_info(task_logger, f"{el}") | ||
if re.search("(\\d* of \\d* ERROR)", el): | ||
raise DbtExecutionError( | ||
msg=f"dbt model failed. Review the dbt output.\n{subproc_output.stdout}", | ||
) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.