Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = { file = "LICENSE" }
requires-python = ">= 3.9"
dependencies = [
"attr",
"eodag[all-providers]",
"eodag[all-providers] >= 4.4.0",
"fastapi",
"geojson",
"geojson-pydantic",
Expand Down
5 changes: 5 additions & 0 deletions stac_fastapi/eodag/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from starlette.responses import JSONResponse as StarletteJSONResponse

from eodag.types.stac_metadata import create_stac_metadata_model
from eodag.utils import StreamResponseContent
from stac_fastapi.eodag.config import get_settings
from stac_fastapi.eodag.core import EodagCoreClient
from stac_fastapi.eodag.dag import init_dag
Expand Down Expand Up @@ -133,6 +134,10 @@ def get_enabled_extensions(specif_extensions: dict):
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
"""API init and tear-down"""
# Register SIGINT/SIGTERM handlers so in-flight download streams are
# interrupted on graceful shutdown. Must run on the main thread.
StreamResponseContent.install_signal_handlers()

init_dag(app)
if os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT", ""):
from stac_fastapi.eodag.telemetry import instrument_eodag
Expand Down
17 changes: 17 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ async def test_liveness_probe(app_client):
assert response.json()["message"] == "PONG"


async def test_lifespan_installs_stream_signal_handlers(mocker):
"""The app lifespan must install the stream interrupt signal handlers."""
from fastapi import FastAPI

from stac_fastapi.eodag.app import lifespan

app = FastAPI()
mock_init_dag = mocker.patch("stac_fastapi.eodag.app.init_dag")
mock_install = mocker.patch("stac_fastapi.eodag.app.StreamResponseContent.install_signal_handlers")

async with lifespan(app):
pass

mock_init_dag.assert_called_once()
mock_install.assert_called_once_with()


async def test_conformance(request_valid):
"""Request to /conformance should return a valid response"""
await request_valid("conformance", check_links=False)
Expand Down
Loading