Skip to content

Commit f11adfb

Browse files
authored
Merge pull request #127 from UW-Macrostrat/bugfix/ingestion-errors
Starting point to fix ingestion errors
2 parents 64d65e1 + d11eb32 commit f11adfb

File tree

5 files changed

+225
-53
lines changed

5 files changed

+225
-53
lines changed

cli/macrostrat/cli/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from macrostrat.core.database import get_database
88

9-
cli = Typer(name="cache")
9+
cli = Typer(name="cache", help="Tile cache management")
1010

1111

1212
@cli.command(name="clear")

local-root/docker-compose.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ services:
8585
- PGRST_DB_MAX_ROWS=5000
8686
- PGRST_SERVER_HOST=
8787
- PGRST_SERVER_TIMING_ENABLED=true
88-
# This is sketchy
88+
# This is sketchy; we really only want this for a few (auth-gated) routes
89+
# Perhaps we can put this config in the database?
8990
- PGRST_DB_AGGREGATES_ENABLED=true
9091
# Tileserver
9192
tileserver:
@@ -94,6 +95,8 @@ services:
9495
context: ${MACROSTRAT_TILESERVER_SRC:-""}
9596
environment:
9697
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/${POSTGRES_DB}
98+
# Ideally the system would fail gracefully if we didn't provide the Rockd database URL but that's not the case.
99+
- ROCKD_DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/rockd
97100
# The `--proxy-headers` flag is necessary for the tileserver to work behind a reverse proxy
98101
# and correctly notify the app that it should trust the X-Forwarded-Proto header.
99102
# This is necessary for the tileserver to correctly generate URLs for tilejson files.

map-integration/macrostrat/map_integration/pipeline.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import csv
99
import datetime
1010
import hashlib
11+
import importlib
1112
import os
1213
import pathlib
1314
import re
@@ -19,7 +20,6 @@
1920
from contextlib import contextmanager
2021
from typing import Annotated, Any, NoReturn, Optional
2122

22-
import magic
2323
import requests # type: ignore[import-untyped]
2424
from rich.console import Console
2525
from sqlalchemy import and_, insert, select, update
@@ -42,9 +42,12 @@
4242
from macrostrat.map_integration.errors import IngestError
4343
from macrostrat.map_integration.process.geometry import create_rgeom, create_webgeom
4444
from macrostrat.map_integration.utils.map_info import MapInfo, get_map_info
45-
4645
from .config import get_minio_client
4746

47+
# Do this with importlib so we control the order
48+
for mod in ["pylibmagic", "magic"]:
49+
importlib.import_module("magic")
50+
4851
# The list of arguments to upload_file that ingest_csv will look
4952
# for in the CSV file given to it.
5053
FIELDS = [
@@ -345,6 +348,7 @@ def get_source_by_slug(slug: str) -> Optional[Sources]:
345348

346349
def create_source(**data) -> Sources:
347350
data = truncate_source_metadata(data)
351+
print(data)
348352
with get_db_session() as session:
349353
new_source = session.scalar(
350354
insert(Sources).values(**data).returning(Sources),
@@ -451,6 +455,7 @@ def create_slug(
451455
metadata["raster_url"] = raster_url
452456

453457
if source := get_source_by_slug(slug):
458+
console.print(f"Found existing source ID {source.source_id} for slug {slug}")
454459
source = update_source(source.source_id, **metadata)
455460
else:
456461
source = create_source(**metadata)
@@ -644,6 +649,8 @@ def upload_file(
644649
raster_url=raster_url,
645650
)
646651

652+
console.print(f"Created record for map {slug}")
653+
647654
## Collect metadata for the archive file.
648655

649656
mime_type = magic.Magic(mime=True).from_file(local_file)

map-integration/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ typer = "^0.12.0"
2222

2323
minio = "^7.2.5"
2424
python-dotenv = "^1"
25+
26+
# Python-Magic does not ship shared library, but Pylibmagic packages
27+
# it to fill the gap.
28+
pylibmagic = "^0.5.0"
2529
python-magic = "^0.4.27"
2630
pyyaml = "^6.0"
2731
shapely = "^2.0.1"

0 commit comments

Comments
 (0)