Skip to content

Commit

Permalink
Improve human readabilty of output: print how long it took to apply h…
Browse files Browse the repository at this point in the history
…ow many changes, and print the rate
  • Loading branch information
amandasaurus committed Jun 20, 2023
1 parent 2bd2e22 commit 4df7b0f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions scripts/osm2pgsql-replication
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def update(conn, args):
return 1

base_url, seq, ts = cur.fetchone()
initial_local_timestamp = ts
LOG.info("Using replication service '%s'.", base_url)
local_db_age_sec = int((dt.datetime.now(dt.timezone.utc) - ts).total_seconds())
LOG.info("Local database is at sequence %d, which is data up until %s ago (%d seconds ago, %s).",
Expand Down Expand Up @@ -396,6 +397,8 @@ def update(conn, args):
int((current.timestamp - ts).total_seconds()),
)

update_started = dt.datetime.now(dt.timezone.utc)

if args.diff_file is not None:
outfile = Path(args.diff_file)
else:
Expand Down Expand Up @@ -454,6 +457,23 @@ def update(conn, args):
if args.once:
break


update_duration_sec = (dt.datetime.now(dt.timezone.utc) - update_started).total_seconds()
with conn.cursor() as cur:
cur.execute(sql.SQL('SELECT * FROM {}').format(args.table))
if cur.rowcount != 1:
LOG.fatal("Updates not set up correctly. Run 'osm2pgsql-updates init' first.")
return 1

_base_url, _seq, current_local_timestamp = cur.fetchone()

total_applied_changes_duration_sec = (current_local_timestamp - initial_local_timestamp).total_seconds()
LOG.info("It took %s (%d sec) to apply %s (%d sec) of changes. This is a speed of ×%.1f.",
pretty_format_timedelta(update_duration_sec), int(update_duration_sec),
pretty_format_timedelta(total_applied_changes_duration_sec), int(total_applied_changes_duration_sec),
total_applied_changes_duration_sec / update_duration_sec
)

return 0

def get_parser():
Expand Down

0 comments on commit 4df7b0f

Please sign in to comment.