From 379c97d8830ff537e0d7a1dfded2f0eaff16d4b9 Mon Sep 17 00:00:00 2001 From: Anuj-Gupta4 Date: Wed, 25 Dec 2024 12:40:39 +0545 Subject: [PATCH 1/3] feat: add background task for basemap generation during project file generation --- src/backend/app/projects/project_routes.py | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index 0f8e5032f..dda961772 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -843,6 +843,7 @@ async def add_additional_entity_list( async def generate_files( db: Annotated[Connection, Depends(db_conn)], project_user_dict: Annotated[ProjectUserDict, Depends(project_manager)], + background_tasks: BackgroundTasks, xlsform_upload: Annotated[ Optional[BytesIO], Depends(central_deps.read_optional_xlsform) ], @@ -867,6 +868,7 @@ async def generate_files( created (i.e. the project form references multiple geometries). db (Connection): The database connection. project_user_dict (ProjectUserDict): Project admin role. + background_tasks (BackgroundTasks): FastAPI background tasks. Returns: json (JSONResponse): A success message containing the project ID. @@ -942,6 +944,13 @@ async def generate_files( }, ) + if project.custom_tms_url: + basemap_in = project_schemas.BasemapGenerate( + tile_source="tms", file_format="pmtiles", tms_url=project.custom_tms_url + ) + org_id = project.organisation_id + await generate_basemap(project_id, org_id, basemap_in, db, background_tasks) + return JSONResponse( status_code=HTTPStatus.OK, content={"message": "success"}, @@ -961,7 +970,19 @@ async def generate_project_basemap( project_id = project_user.get("project").id org_id = project_user.get("project").organisation_id + await generate_basemap(project_id, org_id, basemap_in, db, background_tasks) # Create task in db and return uuid + return {"Message": "Tile generation started"} + + +async def generate_basemap( + project_id: int, + org_id: int, + basemap_in: project_schemas.BasemapGenerate, + db: Connection, + background_tasks: BackgroundTasks, +): + """Generate basemap tiles for a project.""" log.debug( "Creating generate_project_basemap background task " f"for project ID: {project_id}" @@ -985,8 +1006,6 @@ async def generate_project_basemap( basemap_in.tms_url, ) - return {"Message": "Tile generation started"} - @router.patch("/{project_id}", response_model=project_schemas.ProjectOut) async def update_project( From f12facceee538d77a5713f5b6cb840be2c8a7b42 Mon Sep 17 00:00:00 2001 From: Anuj-Gupta4 Date: Wed, 25 Dec 2024 13:05:26 +0545 Subject: [PATCH 2/3] feat: add 'tms' option to tile_source for basemap generation --- src/backend/app/projects/project_schemas.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/app/projects/project_schemas.py b/src/backend/app/projects/project_schemas.py index 70f82866a..13c1ea5c5 100644 --- a/src/backend/app/projects/project_schemas.py +++ b/src/backend/app/projects/project_schemas.py @@ -274,7 +274,9 @@ class ProjectUserContributions(BaseModel): class BasemapGenerate(BaseModel): """Params to generate a new basemap.""" - tile_source: Annotated[Literal["esri", "bing", "google"], Field(default="esri")] + tile_source: Annotated[ + Literal["esri", "bing", "google", "tms"], Field(default="esri") + ] file_format: Annotated[ Literal["mbtiles", "sqlitedb", "pmtiles"], Field(default="mbtiles"), From 81d44790e46c0d45eb80a10a73c6d41da00970fb Mon Sep 17 00:00:00 2001 From: Anuj-Gupta4 Date: Fri, 27 Dec 2024 15:37:03 +0545 Subject: [PATCH 3/3] feat: update basemap generation to support custom tile source --- src/backend/app/projects/project_routes.py | 2 +- src/backend/app/projects/project_schemas.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index dda961772..38aeeda8d 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -946,7 +946,7 @@ async def generate_files( if project.custom_tms_url: basemap_in = project_schemas.BasemapGenerate( - tile_source="tms", file_format="pmtiles", tms_url=project.custom_tms_url + tile_source="custom", file_format="pmtiles", tms_url=project.custom_tms_url ) org_id = project.organisation_id await generate_basemap(project_id, org_id, basemap_in, db, background_tasks) diff --git a/src/backend/app/projects/project_schemas.py b/src/backend/app/projects/project_schemas.py index 13c1ea5c5..f860245bf 100644 --- a/src/backend/app/projects/project_schemas.py +++ b/src/backend/app/projects/project_schemas.py @@ -275,7 +275,7 @@ class BasemapGenerate(BaseModel): """Params to generate a new basemap.""" tile_source: Annotated[ - Literal["esri", "bing", "google", "tms"], Field(default="esri") + Literal["esri", "bing", "google", "custom"], Field(default="esri") ] file_format: Annotated[ Literal["mbtiles", "sqlitedb", "pmtiles"],