File tree Expand file tree Collapse file tree 7 files changed +199
-9
lines changed Expand file tree Collapse file tree 7 files changed +199
-9
lines changed Original file line number Diff line number Diff line change @@ -179,7 +179,7 @@ EXPOSE 8080
179
179
180
180
ENV DJANGO_SETTINGS_MODULE=project.settings.production
181
181
182
- ENV GUNICORN_CMD_ARGS="--bind 0.0.0.0:8080 --workers 2 --max-requests 120 --max-requests-jitter 20 --timeout 8"
182
+ ENV GUNICORN_CMD_ARGS="--bind 0.0.0.0:8080 --workers 4 -k uvicorn_worker.UvicornWorker --max-requests 120 --max-requests-jitter 20 --timeout 8"
183
183
184
184
RUN chmod +x scripts/start_server.sh
185
185
# See <https://hynek.me/articles/docker-signals/>.
Original file line number Diff line number Diff line change @@ -38,11 +38,17 @@ backend/install: bin/uv .venv ## Install the Python dependencies (via uv) and in
38
38
@${SUB_MAKE} .venv/bin/black
39
39
40
40
.PHONY : backend/watch
41
+ backend/watch : env_vars ?=
41
42
backend/watch : address ?= localhost
42
43
backend/watch : port ?= 8000
43
44
backend/watch : dotenv_file ?= .env.local
44
- backend/watch : # # Start the Django development server
45
- @${SUB_MAKE} django/manage cmd=' runserver ${address}:${port}'
45
+ backend/watch : # # Start Django via Uvicorn, in "watch" mode
46
+ @@DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE} ${env_vars} \
47
+ ${UV} run uvicorn \
48
+ --reload --reload-dir src/ \
49
+ --host ${address} --port ${port} \
50
+ --env-file ${dotenv_file} \
51
+ project.asgi:application
46
52
47
53
.PHONY : backend/resetdb
48
54
backend/resetdb : dotenv_file ?= .env.local
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ dependencies= [
14
14
# Django doesn't follow SemVer, so we need to specify the minor version:
15
15
" Django==5.1.*" ,
16
16
" gunicorn==22.*" ,
17
+ " uvicorn[standard]==0.30.*" ,
18
+ " uvicorn-worker==0.2.*" ,
17
19
" django-alive==1.*" ,
18
20
" chess==1.*" ,
19
21
" django-htmx==1.*" ,
Original file line number Diff line number Diff line change 7
7
from apps .webui .components .forms_common import csrf_hidden_input
8
8
from apps .webui .components .layout import page
9
9
10
- from ...lichess_api import get_lichess_api_client
10
+ from ... import lichess_api
11
11
from ..misc_ui import detach_lichess_account_form
12
12
from ..svg_icons import ICON_SVG_LOG_IN
13
13
@@ -43,12 +43,12 @@ def lichess_no_account_linked_page(
43
43
)
44
44
45
45
46
- def lichess_account_linked_homepage (
46
+ async def lichess_account_linked_homepage (
47
47
* ,
48
48
request : "HttpRequest" ,
49
49
access_token : "LichessAccessToken" ,
50
50
) -> str :
51
- me = get_lichess_api_client ( access_token ). account . get ( )
51
+ me = await lichess_api . get_lichess_my_account ( access_token )
52
52
53
53
return page (
54
54
div (
Original file line number Diff line number Diff line change 1
1
from typing import TYPE_CHECKING
2
2
3
3
import berserk
4
+ from asgiref .sync import sync_to_async
4
5
5
6
from .models import LICHESS_ACCESS_TOKEN_PREFIX
6
7
@@ -12,7 +13,14 @@ def is_lichess_api_access_token_valid(token: str) -> bool:
12
13
return token .startswith (LICHESS_ACCESS_TOKEN_PREFIX ) and len (token ) > 10
13
14
14
15
15
- def get_lichess_api_client (access_token : "LichessAccessToken" ) -> berserk .Client :
16
+ @sync_to_async (thread_sensitive = False )
17
+ def get_lichess_my_account (
18
+ access_token : "LichessAccessToken" ,
19
+ ) -> berserk .types .AccountInformation :
20
+ return _get_lichess_api_client (access_token ).account .get ()
21
+
22
+
23
+ def _get_lichess_api_client (access_token : "LichessAccessToken" ) -> berserk .Client :
16
24
return _create_lichess_api_client (access_token )
17
25
18
26
Original file line number Diff line number Diff line change 21
21
22
22
23
23
@require_GET
24
- def lichess_home (request : "HttpRequest" ) -> HttpResponse :
24
+ async def lichess_home (request : "HttpRequest" ) -> HttpResponse :
25
25
# Do we have a Lichess API token for this user?
26
26
lichess_access_token = cookie_helpers .get_lichess_api_access_token_from_request (
27
27
request
@@ -30,7 +30,7 @@ def lichess_home(request: "HttpRequest") -> HttpResponse:
30
30
if not lichess_access_token :
31
31
page_content = lichess_no_account_linked_page (request = request )
32
32
else :
33
- page_content = lichess_account_linked_homepage (
33
+ page_content = await lichess_account_linked_homepage (
34
34
request = request ,
35
35
access_token = lichess_access_token ,
36
36
)
You can’t perform that action at this time.
0 commit comments