-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
529 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from frontik.dependencies import HttpClientT | ||
from frontik.dependencies import HttpClient | ||
from frontik.routing import router | ||
|
||
|
||
@router.get('/example') | ||
async def example_page(http_client: HttpClientT) -> dict: | ||
async def example_page(http_client: HttpClient) -> dict: | ||
result = await http_client.get_url('http://example.com', '/') | ||
return {'example': result.status_code} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
import contextvars | ||
from typing import Annotated, Any | ||
|
||
from fastapi import Depends, Request | ||
from http_client import HttpClient | ||
import http_client | ||
from fastapi import Depends | ||
|
||
from frontik.app_integrations.statsd import StatsDClient | ||
from frontik.balancing_client import get_http_client | ||
from frontik.app_integrations import statsd | ||
|
||
clients: contextvars.ContextVar = contextvars.ContextVar('clients') | ||
|
||
async def get_app_config(request: Request) -> Any: | ||
return request.app.config | ||
|
||
def get_app_config() -> Any: | ||
return clients.get().get('app_config') | ||
|
||
async def get_statsd_client(request: Request) -> StatsDClient: | ||
return request.app.statsd_client | ||
|
||
async def _get_app_config() -> Any: | ||
return get_app_config() | ||
|
||
StatsDClientT = Annotated[StatsDClient, Depends(get_statsd_client)] | ||
AppConfig = Annotated[Any, Depends(get_app_config)] | ||
HttpClientT = Annotated[HttpClient, Depends(get_http_client())] | ||
|
||
def get_http_client() -> http_client.HttpClient: | ||
return clients.get().get('http_client') | ||
|
||
|
||
async def _get_http_client() -> http_client.HttpClient: | ||
return get_http_client() | ||
|
||
|
||
def get_statsd_client() -> statsd.StatsDClient: | ||
return clients.get().get('statsd_client') | ||
|
||
|
||
async def _get_statsd_client() -> statsd.StatsDClient: | ||
return get_statsd_client() | ||
|
||
|
||
StatsDClient = Annotated[statsd.StatsDClient, Depends(_get_statsd_client)] | ||
AppConfig = Annotated[Any, Depends(_get_app_config)] | ||
HttpClient = Annotated[http_client.HttpClient, Depends(_get_http_client)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from contextlib import contextmanager | ||
|
||
from frontik.dependencies import clients | ||
from frontik.request_integrations.integrations_dto import IntegrationDto | ||
|
||
|
||
@contextmanager | ||
def clients_ctx(_frontik_app, _tornado_request): | ||
token = clients.set({}) | ||
try: | ||
yield IntegrationDto() | ||
finally: | ||
clients.reset(token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.