Skip to content

Commit 22e8aa4

Browse files
committed
Update to handle error when data is too stale to update via replication. Cleanup bad var name
1 parent e53f4cf commit 22e8aa4

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

docker/geofabrik.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def set_date_from_metadata(pbf_file: str):
8888
returncode = helpers.run_command_via_subprocess(cmd=osmium_cmd.split(),
8989
cwd=None,
9090
output_lines=output,
91-
print=False)
91+
print_to_log=False)
9292
if returncode != 0:
9393
logger.error(f'osmium fileinfo failed. Output: {output}')
9494

docker/helpers.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ def get_today() -> str:
2727
return today
2828

2929

30-
def run_command_via_subprocess(cmd: list, cwd: str, output_lines: list=[],
31-
print: bool=False) -> int:
30+
def run_command_via_subprocess(cmd: list,
31+
cwd: str,
32+
output_lines: list=[],
33+
print_to_log: bool=False
34+
) -> int:
3235
"""Wraps around subprocess.Popen() to run commands outside of Python. Prints
3336
output as it goes, returns the status code from the command.
3437
@@ -40,7 +43,7 @@ def run_command_via_subprocess(cmd: list, cwd: str, output_lines: list=[],
4043
Set the working directory, or to None.
4144
output_lines : list
4245
Pass in a list to return the output details.
43-
print : bool
46+
print_to_log : bool
4447
Default False. Set to true to also print to logger
4548
4649
Returns
@@ -60,12 +63,23 @@ def run_command_via_subprocess(cmd: list, cwd: str, output_lines: list=[],
6063
if output:
6164
ln = output.strip().decode('utf-8')
6265
output_lines.append(ln)
63-
if print:
66+
if print_to_log:
6467
logger.info(ln)
68+
69+
# Detects issue reported in https://github.com/rustprooflabs/pgosm-flex/issues/391
70+
# Status code is incorrectly returned is 0, cannot detect
71+
# problem using that method so forcing failure with custom
72+
# status code.
73+
if 'Error during diff download. Bailing out.' in ln:
74+
logger.error('Data in database is too far behind replication service.')
75+
return 999
76+
6577
else:
6678
# Only sleep when there wasn't output
6779
sleep(1)
80+
6881
status = process.poll()
82+
6983
return status
7084

7185

docker/pgosm_flex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def run_replication_update(skip_nested, flex_path):
273273
update_cmd = update_cmd.replace('-d $PGOSM_CONN', f'-d {conn_string}')
274274
returncode = helpers.run_command_via_subprocess(cmd=update_cmd.split(),
275275
cwd=flex_path,
276-
print=True)
276+
print_to_log=True)
277277

278278
if returncode != 0:
279279
err_msg = f'Failure. Return code: {returncode}'
@@ -424,7 +424,7 @@ def run_osm2pgsql(osm2pgsql_command, flex_path, debug):
424424

425425
returncode = helpers.run_command_via_subprocess(cmd=osm2pgsql_command.split(),
426426
cwd=flex_path,
427-
print=True)
427+
print_to_log=True)
428428

429429
if returncode != 0:
430430
err_msg = f'Failed to run osm2pgsql. Return code: {returncode}'
@@ -586,7 +586,7 @@ def check_replication_exists():
586586
return True
587587

588588

589-
def run_osm2pgsql_replication_init(pbf_path, pbf_filename):
589+
def run_osm2pgsql_replication_init(pbf_path: str, pbf_filename: str):
590590
"""Runs osm2pgsql-replication init to support replication mode.
591591
592592
Parameters
@@ -604,7 +604,7 @@ def run_osm2pgsql_replication_init(pbf_path, pbf_filename):
604604

605605
returncode = helpers.run_command_via_subprocess(cmd=init_cmd.split(),
606606
cwd=None,
607-
print=True)
607+
print_to_log=True)
608608

609609
if returncode != 0:
610610
err_msg = f'Failed to run osm2pgsql-replication. Return code: {returncode}'

0 commit comments

Comments
 (0)