Skip to content

Commit 0cce479

Browse files
committed
add a post-processing option for the update script
Setups that process expiry data need to do that after each run of osm2pgsql. The new option provides the means to insert additional operations via a script when osm2pgsql is run multiple times.
1 parent b82f223 commit 0cce479

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

scripts/osm2pgsql-replication

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ def update(conn, args):
184184
Any additional arguments to osm2pgsql need to be given after '--'. Database
185185
and the prefix parameter are handed through to osm2pgsql. They do not need
186186
to be repeated. '--append' and '--slim' will always be added as well.
187+
188+
Use the '--post-processing' parameter to execute a script after osm2pgsql has
189+
run successfully. If the updates consists of multiple runs because the
190+
maximum size of downloaded data was reached, then the script is executed
191+
each time that osm2pgsql has run. When the post-processing fails, then
192+
the entire update run is considered a failure and the replication information
193+
is not updated. That means that when 'update' is run the next time it will
194+
recommence with downloading the diffs again and reapplying them to the
195+
database. This is usually safe. The script receives two parameters:
196+
the sequence ID and timestamp of the last successful run. The timestamp
197+
may be missing in the rare case that the replication service stops responding
198+
after the updates have been downloaded.
187199
"""
188200
with conn.cursor() as cur:
189201
cur.execute('SELECT * FROM pg_tables where tablename = %s', (args.table, ))
@@ -244,6 +256,13 @@ def update(conn, args):
244256
seq = endseq
245257

246258
nextstate = repl.get_state_info(seq)
259+
timestamp = nextstate.timestamp if nextstate else None
260+
261+
if args.post_processing:
262+
cmd = [args.post_processing, str(endseq), str(timestamp or '')]
263+
LOG.debug('Calling post-processing script: %s', ' '.join(cmd))
264+
subprocess.run(cmd, check=True)
265+
247266
update_replication_state(conn, args.table, seq,
248267
nextstate.timestamp if nextstate else None)
249268

@@ -318,6 +337,8 @@ def get_parser():
318337
help='Path to osm2pgsql command (default: osm2pgsql)')
319338
cmd.add_argument('--once', action='store_true',
320339
help='Run updates only once, even when more data is available.')
340+
cmd.add_argument('--post-processing', metavar='SCRIPT',
341+
help='Post-processing script to run after each execution of osm2pgsql.')
321342

322343
return parser
323344

0 commit comments

Comments
 (0)