Skip to content
Merged
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
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ dev-dependencies = [
[tool.ruff]
line-length = 88

[tool.ruff.lint.isort]
known-first-party = ['fastapi_utils']

[tool.ruff.lint.mccabe]
max-complexity = 10

Expand Down
32 changes: 19 additions & 13 deletions src/edge_proxy/server.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from datetime import datetime, timedelta
import asyncio

import httpx
import structlog
from contextlib import asynccontextmanager
from fastapi import FastAPI, Header
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware
from fastapi.responses import ORJSONResponse

from edge_proxy.health_check.responses import HealthCheckResponse
from fastapi_utils.tasks import repeat_every

from edge_proxy.cache import LocalMemEnvironmentsCache
from edge_proxy.environments import EnvironmentService
Expand All @@ -24,7 +24,23 @@
httpx.AsyncClient(timeout=settings.api_poll_timeout_seconds),
settings,
)
app = FastAPI()


async def poll_environments():
while True:
await environment_service.refresh_environment_caches()
await asyncio.sleep(settings.api_poll_frequency_seconds)


@asynccontextmanager
async def lifespan(app: FastAPI):
await environment_service.refresh_environment_caches()
poll = asyncio.create_task(poll_environments())
yield
poll.cancel()


app = FastAPI(lifespan=lifespan)


@app.exception_handler(FlagsmithUnknownKeyError)
Expand Down Expand Up @@ -103,16 +119,6 @@ async def get_identities(
return ORJSONResponse(data)


@app.on_event("startup")
@repeat_every(
seconds=settings.api_poll_frequency_seconds,
raise_exceptions=True,
logger=structlog.get_logger(__name__),
)
async def refresh_cache():
await environment_service.refresh_environment_caches()


app.add_middleware(
CORSMiddleware,
allow_origins=settings.allow_origins,
Expand Down
21 changes: 0 additions & 21 deletions src/fastapi_utils/LICENSE

This file was deleted.

77 changes: 0 additions & 77 deletions src/fastapi_utils/tasks.py

This file was deleted.

87 changes: 0 additions & 87 deletions src/fastapi_utils/test_tasks.py

This file was deleted.