Skip to content

Commit

Permalink
fix: only log errors if there were some
Browse files Browse the repository at this point in the history
  • Loading branch information
ahal committed May 7, 2024
1 parent 46d949e commit fd07478
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/fxci_etl/pulse/handlers/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def from_dict(cls, data: dict[str, Any]) -> "Record":
@abstractmethod
def table_name(cls) -> str: ...

@abstractmethod
def __str__(self) -> str: ...


@dataclass
class Run(Record):
Expand All @@ -39,6 +42,9 @@ class Run(Record):
def table_name(cls):
return "task_runs"

def __str__(self):
return f"{self.taskId} run {self.runId}"


@dataclass
class Task(Record):
Expand All @@ -54,6 +60,9 @@ class Task(Record):
def table_name(cls):
return "tasks"

def __str__(self):
return self.taskId


@register()
class BigQueryHandler(PulseHandler):
Expand All @@ -72,7 +81,10 @@ def __init__(self, config: Config):
def insert(self, row: Record):
table = self.tables[row.table_name()]
errors = self.client.insert_rows(table, [asdict(row)])
pprint(errors, indent=2)
if errors:
pprint(errors, indent=2)
else:
print(f"Inserted: {row}")

def __call__(self, data, message):
run_record = {"taskId": data["status"]["taskId"]}
Expand Down

0 comments on commit fd07478

Please sign in to comment.