housekeep: reformat files with pre-hooks

Signed-off-by: Leonidas Spyropoulos <artafinde@archlinux.org>
This commit is contained in:
Leonidas Spyropoulos 2024-08-03 08:15:56 +01:00
parent 4d5909256f
commit a54b6935a1
No known key found for this signature in database
GPG key ID: 244740D17C7FD0EC
4 changed files with 55 additions and 54 deletions

View file

@ -1,7 +1,7 @@
import pickle import pickle
from typing import Any, Callable
from sqlalchemy import orm from sqlalchemy import orm
from typing import Callable, Any
from aurweb import config from aurweb import config
from aurweb.aur_redis import redis_connection from aurweb.aur_redis import redis_connection

View file

@ -81,7 +81,9 @@ async def rss_modified(request: Request):
# we use redis for caching the results of the feedgen # we use redis for caching the results of the feedgen
cache_expire = config.getint("cache", "expiry_time_rss", 300) cache_expire = config.getint("cache", "expiry_time_rss", 300)
feed = lambda_cache("rss_modified", lambda: make_rss_feed(request, packages), cache_expire) feed = lambda_cache(
"rss_modified", lambda: make_rss_feed(request, packages), cache_expire
)
response = Response(feed, media_type="application/rss+xml") response = Response(feed, media_type="application/rss+xml")
return response return response

View file

@ -51,46 +51,46 @@ def generate_nginx_config():
fastapi_bind = aurweb.config.get("fastapi", "bind_address") fastapi_bind = aurweb.config.get("fastapi", "bind_address")
fastapi_host = fastapi_bind.split(":")[0] fastapi_host = fastapi_bind.split(":")[0]
config_path = os.path.join(temporary_dir, "nginx.conf") config_path = os.path.join(temporary_dir, "nginx.conf")
config = open(config_path, "w") with open(config_path, "w") as config:
# We double nginx's braces because they conflict with Python's f-strings. # We double nginx's braces because they conflict with Python's f-strings.
config.write( config.write(
f""" f"""
events {{}} events {{}}
daemon off; daemon off;
error_log /dev/stderr info; error_log /dev/stderr info;
pid {os.path.join(temporary_dir, "nginx.pid")}; pid {os.path.join(temporary_dir, "nginx.pid")};
http {{ http {{
access_log /dev/stdout; access_log /dev/stdout;
client_body_temp_path {os.path.join(temporary_dir, "client_body")}; client_body_temp_path {os.path.join(temporary_dir, "client_body")};
proxy_temp_path {os.path.join(temporary_dir, "proxy")}; proxy_temp_path {os.path.join(temporary_dir, "proxy")};
fastcgi_temp_path {os.path.join(temporary_dir, "fastcgi")}1 2; fastcgi_temp_path {os.path.join(temporary_dir, "fastcgi")}1 2;
uwsgi_temp_path {os.path.join(temporary_dir, "uwsgi")}; uwsgi_temp_path {os.path.join(temporary_dir, "uwsgi")};
scgi_temp_path {os.path.join(temporary_dir, "scgi")}; scgi_temp_path {os.path.join(temporary_dir, "scgi")};
server {{ server {{
listen {fastapi_host}:{FASTAPI_NGINX_PORT}; listen {fastapi_host}:{FASTAPI_NGINX_PORT};
location / {{ location / {{
try_files $uri @proxy_to_app; try_files $uri @proxy_to_app;
}} }}
location @proxy_to_app {{ location @proxy_to_app {{
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off; proxy_redirect off;
proxy_buffering off; proxy_buffering off;
proxy_pass http://{fastapi_bind}; proxy_pass http://{fastapi_bind};
}}
}} }}
}} }}
}} """
""" )
)
return config_path return config_path
def spawn_child(args): def spawn_child(_args):
"""Open a subprocess and add it to the global state.""" """Open a subprocess and add it to the global state."""
if verbosity >= 1: if verbosity >= 1:
print(f":: Spawning {args}", file=sys.stderr) print(f":: Spawning {_args}", file=sys.stderr)
children.append(subprocess.Popen(args)) children.append(subprocess.Popen(_args))
def start(): def start():
@ -171,17 +171,17 @@ def start():
) )
def _kill_children( def _kill_children(_children: Iterable, exceptions=None) -> list[Exception]:
children: Iterable, exceptions: list[Exception] = []
) -> list[Exception]:
""" """
Kill each process found in `children`. Kill each process found in `children`.
:param children: Iterable of child processes :param _children: Iterable of child processes
:param exceptions: Exception memo :param exceptions: Exception memo
:return: `exceptions` :return: `exceptions`
""" """
for p in children: if exceptions is None:
exceptions = []
for p in _children:
try: try:
p.terminate() p.terminate()
if verbosity >= 1: if verbosity >= 1:
@ -191,17 +191,17 @@ def _kill_children(
return exceptions return exceptions
def _wait_for_children( def _wait_for_children(_children: Iterable, exceptions=None) -> list[Exception]:
children: Iterable, exceptions: list[Exception] = []
) -> list[Exception]:
""" """
Wait for each process to end found in `children`. Wait for each process to end found in `children`.
:param children: Iterable of child processes :param _children: Iterable of child processes
:param exceptions: Exception memo :param exceptions: Exception memo
:return: `exceptions` :return: `exceptions`
""" """
for p in children: if exceptions is None:
exceptions = []
for p in _children:
try: try:
rc = p.wait() rc = p.wait()
if rc != 0 and rc != -15: if rc != 0 and rc != -15:

View file

@ -1,30 +1,29 @@
"""add indicies on PackageBases for RSS order by """add indices on PackageBases for RSS order by
Revision ID: 38e5b9982eea Revision ID: 38e5b9982eea
Revises: 7d65d35fae45 Revises: 7d65d35fae45
Create Date: 2024-08-03 01:35:39.104283 Create Date: 2024-08-03 01:35:39.104283
""" """
from alembic import op from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '38e5b9982eea' revision = "38e5b9982eea"
down_revision = '7d65d35fae45' down_revision = "7d65d35fae45"
branch_labels = None branch_labels = None
depends_on = None depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_index('BasesModifiedTS', 'PackageBases', ['ModifiedTS'], unique=False) op.create_index("BasesModifiedTS", "PackageBases", ["ModifiedTS"], unique=False)
op.create_index('BasesSubmittedTS', 'PackageBases', ['SubmittedTS'], unique=False) op.create_index("BasesSubmittedTS", "PackageBases", ["SubmittedTS"], unique=False)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.drop_index('BasesSubmittedTS', table_name='PackageBases') op.drop_index("BasesSubmittedTS", table_name="PackageBases")
op.drop_index('BasesModifiedTS', table_name='PackageBases') op.drop_index("BasesModifiedTS", table_name="PackageBases")
# ### end Alembic commands ### # ### end Alembic commands ###