Split last_upsert (persisted write) and last_refresh (run liveness) in stats
This commit is contained in:
+12
-4
@@ -145,17 +145,23 @@ class CachingEngine:
|
||||
def stats(self) -> Stats:
|
||||
states = self._cache.get_states()
|
||||
errors = self._cache.get_errors()
|
||||
last_runs = self._cache.get_last_runs()
|
||||
with self._cache._lock:
|
||||
base = self._stats.snapshot(self._cache.connection, states)
|
||||
base = replace(base, errors=self._cache.error_total)
|
||||
return replace(
|
||||
base, tables={n: self._enrich(n, t, errors) for n, t in base.tables.items()}
|
||||
base,
|
||||
tables={n: self._enrich(n, t, errors, last_runs) for n, t in base.tables.items()},
|
||||
)
|
||||
|
||||
def _enrich(
|
||||
self, name: str, table_stats: TableStats, errors: dict[str, TableError]
|
||||
self,
|
||||
name: str,
|
||||
table_stats: TableStats,
|
||||
errors: dict[str, TableError],
|
||||
last_runs: dict[str, str],
|
||||
) -> TableStats:
|
||||
"""Annotate a TableStats with refresh tracking, TTL staleness and errors."""
|
||||
"""Annotate a TableStats with refresh tracking, TTL staleness, errors and run time."""
|
||||
if name in self._delta:
|
||||
tracking = "delta"
|
||||
elif name in self._ttl:
|
||||
@@ -169,17 +175,19 @@ class CachingEngine:
|
||||
if age is not None and age > self._ttl[name]:
|
||||
state = TableState.STALE
|
||||
|
||||
last_refresh = last_runs.get(name)
|
||||
err = errors.get(name)
|
||||
if err is not None:
|
||||
return replace(
|
||||
table_stats,
|
||||
tracking=tracking,
|
||||
state=state,
|
||||
last_refresh=last_refresh,
|
||||
last_error=err.message,
|
||||
last_error_at=err.at,
|
||||
consecutive_failures=err.consecutive,
|
||||
)
|
||||
return replace(table_stats, tracking=tracking, state=state)
|
||||
return replace(table_stats, tracking=tracking, state=state, last_refresh=last_refresh)
|
||||
|
||||
def execute(self, sql: str, params: Params = None) -> list[dict]:
|
||||
parsed = parse(sql, params, dialect=self._dialect)
|
||||
|
||||
Reference in New Issue
Block a user