Skip to content

Commit

Permalink
Encapsulate second try in layer.db.refresh_table
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Nov 15, 2022
1 parent 630583b commit 934d6ee
Showing 1 changed file with 30 additions and 43 deletions.
73 changes: 30 additions & 43 deletions src/layman/layer/db/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,36 @@ def refresh_table(
main_filepath = main_filepaths[0]
table_name = db.get_table_name(workspace, layername)

process = db.import_layer_vector_file_async(workspace, table_name, main_filepath, crs_id)
while process.poll() is None and not self.is_aborted():
pass
if self.is_aborted():
logger.info(f'terminating {workspace} {layername}')
process.terminate()
logger.info(f'terminating {workspace} {layername}')
table.delete_layer(workspace, layername)
raise AbortedException
return_code = process.poll()
output = process.stdout.read()
if return_code != 0 or output:
info = table.get_layer_info(workspace, layername)
if not info:
pg_error = str(output)
logger.error(f"STDOUT: {pg_error}")
if "ERROR: zero-length delimited identifier at or near" in pg_error:
err_code = 28
raise LaymanError(err_code, private_data=pg_error)
if 'ERROR: invalid byte sequence for encoding "UTF8":' in pg_error:
processes = db.import_layer_vector_file_async_with_iconv(workspace, table_name, main_filepath, crs_id)
_, sterr = processes[-1].communicate()
if sterr:
logger.error(f"STDOUT: {str(sterr)}")
if self.is_aborted():
logger.info(f'terminating {workspace} {layername}')
for proc in processes:
proc.terminate()
logger.info(f'terminating {workspace} {layername}')
table.delete_layer(workspace, layername)
raise AbortedException
return_code = process.poll()
output = process.stdout.read()
if return_code != 0 or output:
info = table.get_layer_info(workspace, layername)
if not info:
pg_error = str(output)
logger.error(f"STDOUT: {pg_error}")
err_code = 11
raise LaymanError(err_code, private_data=pg_error)
else:
err_code = 11
raise LaymanError(err_code, private_data=pg_error)
for try_num in [1, 2]:
if try_num == 1:
processes = [db.import_layer_vector_file_async(workspace, table_name, main_filepath, crs_id)]
elif try_num == 2:
processes = db.import_layer_vector_file_async_with_iconv(workspace, table_name, main_filepath, crs_id)
process = processes[-1]
stdout, stderr = process.communicate()
return_code = process.poll()
if self.is_aborted():
logger.info(f'terminating {workspace} {layername}')
for proc in processes:
proc.terminate()
logger.info(f'deleting {workspace} {layername}')
table.delete_layer(workspace, layername)
raise AbortedException
if return_code != 0 or stdout or stderr:
info = table.get_layer_info(workspace, layername)
if not info:
str_error = str(stderr)
str_out = str(stdout)
logger.error(f"STDOUT: {str(stdout)}")
logger.error(f"STDERR: {str_error}")
if "ERROR: zero-length delimited identifier at or near" in str_out:
err_code = 28
elif 'ERROR: invalid byte sequence for encoding "UTF8":' in str_out:
continue
else:
err_code = 11
raise LaymanError(err_code, private_data=str_error)
break

crs = db.get_crs(workspace, table_name)
if crs_def.CRSDefinitions[crs].srid:
Expand Down

0 comments on commit 934d6ee

Please sign in to comment.