Skip to content

Commit a51859e

Browse files
fix(bug): replication timestamp
fixes bug on last_ts date when changeset is upserted
1 parent 3759bf4 commit a51859e

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

api/queries.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,17 @@ def _user_stats_sql(*, filter_dates: bool, filter_hashtags: bool, include_tags:
137137

138138

139139
async def fetch_state() -> dict[str, Any] | None:
140+
# last_ts/last_seq come from the worst-lagging source (slowest source bounds real freshness);
141+
# updated_at is the most recent heartbeat across all sources (any tick proves the worker is alive).
140142
async with get_pool().acquire() as conn:
141-
row = await conn.fetchrow("SELECT last_seq, last_ts, updated_at FROM state ORDER BY updated_at DESC LIMIT 1")
143+
row = await conn.fetchrow(
144+
"""
145+
SELECT last_seq, last_ts, (SELECT MAX(updated_at) FROM state) AS updated_at
146+
FROM state
147+
ORDER BY last_ts ASC
148+
LIMIT 1
149+
"""
150+
)
142151
if row is None:
143152
return None
144153
return dict(row)

osmsg/pipeline.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def run(cfg: RunConfig) -> dict[str, Any]:
408408
conn,
409409
source_url=CHANGESETS_REPLICATION,
410410
last_seq=cs_end,
411-
last_ts=cfg.end_date.astimezone(UTC),
411+
last_ts=cs_repl.sequence_to_timestamp(cs_end),
412412
updated_at=dt.datetime.now(UTC),
413413
)
414414
info("Changeset processing complete.")
@@ -439,6 +439,15 @@ def run(cfg: RunConfig) -> dict[str, Any]:
439439

440440
if not urls:
441441
info(f" {url}: already up-to-date")
442+
if resume_seq is not None:
443+
# Heartbeat: bump updated_at so /health can tell "alive, idle" apart from "stuck".
444+
upsert_state(
445+
conn,
446+
source_url=url,
447+
last_seq=resume_seq - 1,
448+
last_ts=url_start,
449+
updated_at=dt.datetime.now(UTC),
450+
)
442451
continue
443452

444453
cf_dir.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)