Skip to content

Commit

Permalink
Test fastapi
Browse files Browse the repository at this point in the history
  • Loading branch information
talsabagport committed Nov 10, 2024
1 parent 12d2c19 commit 27a848f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
3 changes: 3 additions & 0 deletions integrations/jira/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ async def handle_webhook_request(data: dict[str, Any]) -> dict[str, Any]:
return {"ok": True}


ocean.app.fast_api_app.include_router(ocean.router, prefix="/integration")


# Called once when the integration starts.
@ocean.on_start()
async def on_start() -> None:
Expand Down
34 changes: 16 additions & 18 deletions port_ocean/ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,22 @@ def __init__(
config_override: Dict[str, Any] | None = None,
):
initialize_port_ocean_context(self)
self.fast_api_app = app or FastAPI()
self.fast_api_app.middleware("http")(request_handler)

@asynccontextmanager
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
try:
await self.integration.start()
await self._setup_scheduled_resync()
yield None
except Exception:
logger.exception("Integration had a fatal error. Shutting down.")
logger.complete()
sys.exit("Server stopped")
finally:
signal_handler.exit()

self.fast_api_app = app or FastAPI(lifespan=lifespan)
# self.fast_api_app.middleware("http")(request_handler)

self.config = IntegrationConfiguration(
# type: ignore
Expand Down Expand Up @@ -113,20 +127,4 @@ async def execute_resync_all() -> None:
await repeated_function()

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
self.fast_api_app.include_router(self.integration_router, prefix="/integration")

@asynccontextmanager
async def lifecycle(_: FastAPI) -> AsyncIterator[None]:
try:
await self.integration.start()
await self._setup_scheduled_resync()
yield None
except Exception:
logger.exception("Integration had a fatal error. Shutting down.")
logger.complete()
sys.exit("Server stopped")
finally:
signal_handler.exit()

self.fast_api_app.router.lifespan_context = lifecycle
await self.fast_api_app(scope, receive, send)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "port-ocean"
version = "0.12.9"
version = "0.12.9-dev01"
description = "Port Ocean is a CLI tool for managing your Port projects."
readme = "README.md"
homepage = "https://app.getport.io"
Expand Down

0 comments on commit 27a848f

Please sign in to comment.