Updating maps import so previously imported pbf files are reset on import. Ignoring map tile initialization script failure when importing.

This commit is contained in:
Roland 2025-03-13 15:52:40 -06:00
parent 28ec996999
commit d2ae135e5b
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
3 changed files with 26 additions and 17 deletions

View file

@ -94,6 +94,11 @@ async def import_files(paths: List[str]):
any_success = False
try:
if pbfs:
with get_db_session(commit=True) as session:
# Any previously imported PBFs are no longer imported.
for pbf_file in session.query(MapFile):
pbf_file.imported = False
success = False
try:
api_app.shared_ctx.map_importing.update(dict(
@ -115,8 +120,6 @@ async def import_files(paths: List[str]):
for pbf_path in pbfs:
pbf_file = get_or_create_map_file(pbf_path, session)
pbf_file.imported = True
for pbf_file in session.query(MapFile):
pbf_file.imported = pbf_file.path in pbfs
for path in dumps:
# Import each dump individually.

View file

@ -9,7 +9,9 @@ def assert_map_file_status(test_client, expected, status_code=HTTPStatus.OK):
request, response = test_client.get('/api/map/files')
assert response.status_code == status_code
for pbf, expected_ in zip_longest(response.json['files'], expected):
assert pbf['imported'] == expected_['imported']
imported = 'to be imported' if expected_['imported'] else 'to NOT be imported'
if not pbf['imported'] == expected_['imported']:
raise AssertionError(f'Expected {pbf["path"]} {imported}')
assert pbf['path'].endswith(expected_['path'])
assert response.json['pending'] is None
@ -32,21 +34,11 @@ def test_status_and_import(test_client, test_session, make_files_structure, mock
]
assert_map_file_status(test_client, expected)
body = {'files': [str(pbf1), ], }
request, response = test_client.post('/api/map/import', content=json.dumps(body))
assert response.status_code == HTTPStatus.NO_CONTENT
expected = [
{'imported': False, 'path': 'map/dump/dumpy.dump'},
{'imported': False, 'path': 'map/pbf/other-country.osm.pbf'},
{'imported': True, 'path': 'map/pbf/some-country.osm.pbf'},
]
assert_map_file_status(test_client, expected)
body = {'files': [str(pbf1), str(pbf2)]}
request, response = test_client.post('/api/map/import', content=json.dumps(body))
assert response.status_code == HTTPStatus.NO_CONTENT
# Can import multiple pbf files.
expected = [
{'imported': False, 'path': 'map/dump/dumpy.dump'},
{'imported': True, 'path': 'map/pbf/other-country.osm.pbf'},
@ -54,13 +46,26 @@ def test_status_and_import(test_client, test_session, make_files_structure, mock
]
assert_map_file_status(test_client, expected)
body = {'files': [str(pbf1), ], }
request, response = test_client.post('/api/map/import', content=json.dumps(body))
assert response.status_code == HTTPStatus.NO_CONTENT
# Importing one pbf resets the import statuses.
expected = [
{'imported': False, 'path': 'map/dump/dumpy.dump'},
{'imported': False, 'path': 'map/pbf/other-country.osm.pbf'},
{'imported': True, 'path': 'map/pbf/some-country.osm.pbf'},
]
assert_map_file_status(test_client, expected)
body = {'files': [str(dump1), ]}
request, response = test_client.post('/api/map/import', content=json.dumps(body))
assert response.status_code == HTTPStatus.NO_CONTENT
# Importing a dump also resets statuses.
expected = [
{'imported': True, 'path': 'map/dump/dumpy.dump'},
{'imported': True, 'path': 'map/pbf/other-country.osm.pbf'},
{'imported': False, 'path': 'map/pbf/other-country.osm.pbf'},
{'imported': True, 'path': 'map/pbf/some-country.osm.pbf'},
]
assert_map_file_status(test_client, expected)

View file

@ -107,5 +107,6 @@ fi
# Clear map tile cache only after successful import.
yes | /bin/bash /opt/wrolpi/scripts/clear_map_cache.sh
# Use curl to fetch the first few layers of map tiles so the map is ready to use.
bash /opt/wrolpi/wrolpi/scripts/initialize_map_tiles.sh
# Use wget to fetch the first few layers of map tiles so the map is ready to use.
# Failure does not mean the import failed.
bash /opt/wrolpi/wrolpi/scripts/initialize_map_tiles.sh || :