Skip to content

Commit

Permalink
Log warnings and skipped models in addition to errored out models
Browse files Browse the repository at this point in the history
  • Loading branch information
austinweisgrau committed Oct 18, 2023
1 parent 13a214a commit d7b39eb
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions parsons/utilities/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
self.start = time.time()
self.log_messages = []
self.error_messages = []
self.warn_messages = []
self.done_messages = []
self.slack_channel = slack_channel
self.slack_webhook = slack_webhook
Expand Down Expand Up @@ -86,7 +87,14 @@ def seconds_to_time_string(self, seconds: int):

return time_str

def record_result(self, command: str, error_messages: list[str], done_message: str):
def record_result(
self,
command: str,
error_messages: list[str],
warn_messages: list[str],
skip_messages: list[str],
done_message: str,
):
command_seconds = int(
self._command_times[command]["end"] - self._command_times[command]["start"]
)
Expand All @@ -95,6 +103,9 @@ def record_result(self, command: str, error_messages: list[str], done_message: s
if error_messages:
log_message += ":red_circle:"
status = "Error"
elif warn_messages:
log_message += ":large_orange_circle:"
status = "Warning"
else:
log_message += ":large_green_circle:"
status = "Success"
Expand All @@ -106,9 +117,22 @@ def record_result(self, command: str, error_messages: list[str], done_message: s

if error_messages:
log_message += "\nError messages:\n```{}```".format(
"\n".join(error_messages)
"\n\n".join(error_messages)
)

if warn_messages:
log_message += "\nWarning messages:\n```{}```".format(
"\n\n".join(warn_messages)
)

if skip_messages:
skips = [
msg.split(" ")[5].split(".")[1]
for msg in skip_messages
if msg.split(" ")[4] == "relation"
]
log_message += "\nSkipped:\n```{}```".format(", ".join(skips))

self.log_messages.append(log_message)

def send_to_slack(self) -> None:
Expand Down Expand Up @@ -153,6 +177,8 @@ def log_results(self, command_str: str, stdout: str, stderr: str) -> None:

log_messages = []
error_messages = []
warn_messages = []
skip_messages = []

for row in parsed_rows:
if not row["info"]["msg"]:
Expand All @@ -164,6 +190,12 @@ def log_results(self, command_str: str, stdout: str, stderr: str) -> None:
if row["info"]["level"] == "error":
logger.error(log_message)
error_messages.append(log_message)
elif row["info"]["level"] == "warn":
logger.warning(log_message)
warn_messages.append(log_message)
elif "SKIP " in row["info"]["msg"]:
logger.warning(log_message)
skip_messages.append(log_message)
else:
logger.info(log_message)

Expand All @@ -173,7 +205,9 @@ def log_results(self, command_str: str, stdout: str, stderr: str) -> None:
else:
done_message = ""

self.record_result(command_str, error_messages, done_message)
self.record_result(
command_str, error_messages, warn_messages, skip_messages, done_message
)


class dbtRunner:
Expand Down

0 comments on commit d7b39eb

Please sign in to comment.