Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmdlt committed Nov 2, 2024
1 parent d77577b commit b2caedc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 90 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ RUN apt-get update && \
apt-get install -y make && \
pip install uv

ENV UV_LINK_MODE=copy
ENV UV_COMPILE_BYTECODE=1
RUN --mount=type=cache,target=/root/.cache/uv

WORKDIR /app
COPY . .
Expand Down
25 changes: 9 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,27 @@ dev:
run:
uv run gunicorn -w 4 -b 0.0.0.0:$(PORT) app.server:app

start:
make stop rm || true
docker run -p $(PORT):$(PORT) data-charts-api make run

build:
docker build . --tag=data-charts-api

start:
-docker stop data-charts-api
-docker rm data-charts-api
docker run -d --name data-charts-api -p $(PORT):$(PORT) data-charts-api

stop:
docker stop data-charts-api
-docker stop data-charts-api

rm:
docker rm data-charts-api
-docker rm data-charts-api

bash:
docker run --rm -it data-charts-api bash

PID_FILE = server.pid

test:
env PORT=$(PORT) DATABASE_URL=postgres://student:[email protected]:5432/chartsdb \
make dev & echo $$! > $(PID_FILE) && \
sleep 2 && \
uv run pytest; \
status=$$?; \
if [ -f $(PID_FILE) ]; then kill `cat $(PID_FILE)` && rm $(PID_FILE); fi; \
exit $$status
uv run pytest

lint:
uv run ruff check .

check: test lint
check: lint
16 changes: 8 additions & 8 deletions app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def get_visits():
SELECT *
FROM visits
WHERE visits.datetime BETWEEN (%s) AND (%s);'''
conn = get_db()
with conn.cursor(row_factory=dict_row) as c:
c.execute(query, [begin_date, end_date])
res = c.fetchall()
with get_db() as conn:
with conn.cursor(row_factory=dict_row) as c:
c.execute(query, [begin_date, end_date])
res = c.fetchall()
return res


Expand All @@ -57,8 +57,8 @@ def get_registrations():
SELECT *
FROM registrations
WHERE registrations.datetime BETWEEN (%s) AND (%s);'''
conn = get_db()
with conn.cursor(row_factory=dict_row) as c:
c.execute(query, [begin_date, end_date])
res = c.fetchall()
with get_db() as conn:
with conn.cursor(row_factory=dict_row) as c:
c.execute(query, [begin_date, end_date])
res = c.fetchall()
return res
1 change: 0 additions & 1 deletion server.pid

This file was deleted.

63 changes: 0 additions & 63 deletions tests/conftest.py

This file was deleted.

0 comments on commit b2caedc

Please sign in to comment.