Skip to content

Commit

Permalink
Merge pull request #127 from DNO-inc/bodya
Browse files Browse the repository at this point in the history
version 0.8.0 & created scheduler
  • Loading branch information
m-o-d-e-r authored Aug 26, 2023
2 parents 8613143 + 0e94009 commit c7a8216
Show file tree
Hide file tree
Showing 47 changed files with 440 additions and 547 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ burrito_cluster_ps:

changelog:
scripts/generate_changelog.sh

prepare_db:
$(PYTHON) scripts/prepare_db.py
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ touch .env
- `MYSQL_USER`
- `MYSQL_PASSWORD`
- `burrito_redis` - contains access/refresh tokens (no variables are needed)
- Build Burrito API
```bash
docker build . -t burrito
```
- Launch Burrito API
```bash
docker-compose up
docker run --rm burrito
```
- Run tests
```bash
Expand Down Expand Up @@ -85,9 +89,13 @@ touch .env
- `burrito_db` - contain MySQL database (you can find more information about MySql docker container and its environment variables [here](https://hub.docker.com/_/mysql)
- `burrito_nginx` - proxy-server and load balancer for `burrito cluster` (no variables are needed)
- `burrito_redis` - contains access/refresh tokens (no variables are needed)
- Launch needed databases (if you would not setup own) in docker-compose
```bash
docker-compose -f docker-compose-dbs.yml up
```
- Launch Burrito API
```bash
make burrito_cluster_run
docker-compose -f docker-compose-separated.yml up
```
- Run tests
```bash
Expand Down
2 changes: 1 addition & 1 deletion burrito/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.2 indev"
__version__ = "0.8.0 indev"
52 changes: 14 additions & 38 deletions burrito/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,27 @@
"""

from burrito.utils.config_reader import get_config

from burrito.init.init_system import InitManager, get_logger
from burrito.init.tasks.check_db_task import CheckDBTask
from burrito.init.tasks.preprocessor_task import PreProcessorTask


get_config() # read configs

init_manager = InitManager(
error_attempt_delta=3
)
init_manager.add_task(CheckDBTask(attempt_count=100))
init_manager.add_task(PreProcessorTask(attempt_count=100))
import uvicorn

init_manager.run_cycle()
from burrito.apps.registration.router import registration_router
from burrito.apps.about.router import about_router

from burrito.apps.auth.router import auth_router
from burrito.apps.profile.router import profile_router

if not init_manager.critical:
import uvicorn
from burrito.apps.tickets.router import tickets_router
from burrito.apps.admin.router import admin_router

from burrito.apps.registration.router import registration_router
from burrito.apps.about.router import about_router
from burrito.apps.anon.router import anon_router
from burrito.apps.meta.router import meta_router

from burrito.apps.auth.router import auth_router
from burrito.apps.profile.router import profile_router
from burrito.apps.iofiles.router import iofiles_router
from burrito.apps.comments.router import comments_router

from burrito.apps.tickets.router import tickets_router
from burrito.apps.admin.router import admin_router
from burrito.apps.notifications.router import notifications_router

from burrito.apps.anon.router import anon_router
from burrito.apps.meta.router import meta_router

from burrito.apps.iofiles.router import iofiles_router
from burrito.apps.comments.router import comments_router

from burrito.apps.notifications.router import notifications_router

from burrito.utils.app_util import connect_app, get_current_app
else:
print()
get_logger().critical("Some critical error was ocurred before")
exit(1)
from burrito.utils.app_util import connect_app, get_current_app
from burrito.utils.config_reader import get_config


app = get_current_app()
Expand All @@ -71,6 +49,4 @@
host="0.0.0.0",
port=int(get_config().BURRITO_PORT),
proxy_headers=bool(get_config().BURRITO_PROXY_HEADERS),
reload=True,
reload_dirs="burrito"
)
8 changes: 2 additions & 6 deletions burrito/apps/about/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import uvicorn

from burrito.containers import get_current_app_name
from burrito.apps.about.router import about_router
from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


if prepare_app():
from burrito.apps.about.router import about_router
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url=f"/{_APP_NAME}/", openapi_url=f"/{_APP_NAME}/openapi.json")
Expand Down
8 changes: 2 additions & 6 deletions burrito/apps/admin/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import uvicorn

from burrito.containers import get_current_app_name
from burrito.apps.admin.router import admin_router
from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


if prepare_app():
from burrito.apps.admin.router import admin_router
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url=f"/{_APP_NAME}/", openapi_url=f"/{_APP_NAME}/openapi.json")
Expand Down
8 changes: 2 additions & 6 deletions burrito/apps/anon/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import uvicorn

from burrito.containers import get_current_app_name
from burrito.apps.anon.router import anon_router
from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


if prepare_app():
from burrito.apps.anon.router import anon_router
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url=f"/{_APP_NAME}/", openapi_url=f"/{_APP_NAME}/openapi.json")
Expand Down
8 changes: 2 additions & 6 deletions burrito/apps/auth/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import uvicorn

from burrito.containers import get_current_app_name
from burrito.apps.auth.router import auth_router
from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


if prepare_app():
from burrito.apps.auth.router import auth_router
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url=f"/{_APP_NAME}/", openapi_url=f"/{_APP_NAME}/openapi.json")
Expand Down
8 changes: 2 additions & 6 deletions burrito/apps/comments/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import uvicorn

from burrito.containers import get_current_app_name
from burrito.apps.comments.router import comments_router
from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


if prepare_app():
from burrito.apps.comments.router import comments_router
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url=f"/{_APP_NAME}/", openapi_url=f"/{_APP_NAME}/openapi.json")
Expand Down
8 changes: 2 additions & 6 deletions burrito/apps/iofiles/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import uvicorn

from burrito.containers import get_current_app_name
from burrito.apps.iofiles.router import iofiles_router
from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


if prepare_app():
from burrito.apps.iofiles.router import iofiles_router
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url=f"/{_APP_NAME}/", openapi_url=f"/{_APP_NAME}/openapi.json")
Expand Down
8 changes: 2 additions & 6 deletions burrito/apps/meta/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import uvicorn

from burrito.containers import get_current_app_name
from burrito.apps.meta.router import meta_router
from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


if prepare_app():
from burrito.apps.meta.router import meta_router
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url=f"/{_APP_NAME}/", openapi_url=f"/{_APP_NAME}/openapi.json")
Expand Down
8 changes: 2 additions & 6 deletions burrito/apps/notifications/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import uvicorn

from burrito.containers import get_current_app_name
from burrito.apps.notifications.router import notifications_router
from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


if prepare_app():
from burrito.apps.notifications.router import notifications_router
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url=f"/{_APP_NAME}/", openapi_url=f"/{_APP_NAME}/openapi.json")
Expand Down
8 changes: 2 additions & 6 deletions burrito/apps/profile/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import uvicorn

from burrito.containers import get_current_app_name
from burrito.apps.profile.router import profile_router
from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


if prepare_app():
from burrito.apps.profile.router import profile_router
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url=f"/{_APP_NAME}/", openapi_url=f"/{_APP_NAME}/openapi.json")
Expand Down
8 changes: 2 additions & 6 deletions burrito/apps/registration/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import uvicorn

from burrito.containers import get_current_app_name
from burrito.apps.registration.router import registration_router
from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


if prepare_app():
from burrito.apps.registration.router import registration_router
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url=f"/{_APP_NAME}/", openapi_url=f"/{_APP_NAME}/openapi.json")
Expand Down
31 changes: 31 additions & 0 deletions burrito/apps/scheduler/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM python:3.10-slim-buster as burrito-build-base

ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=true \
PATH="/opt/pysetup/.venv/bin:$PATH"

RUN apt-get update
RUN apt-get install --no-install-recommends -y build-essential

WORKDIR /opt/pysetup

RUN pip3 install poetry

COPY pyproject.toml ./

RUN poetry install --only main


FROM python:3.10-slim-buster

ENV PATH="/opt/pysetup/.venv/bin:$PATH"

COPY --from=burrito-build-base /opt/pysetup/ /opt/pysetup/
COPY ./preprocessor_config.json /preprocessor_config.json
COPY ./CONTRIBUTORS.md /CONTRIBUTORS.md
COPY ./CHANGELOG.md /CHANGELOG.md
COPY ./burrito /burrito

WORKDIR ./

CMD ["python", "-m", "burrito.apps.scheduler"]
File renamed without changes.
4 changes: 4 additions & 0 deletions burrito/apps/scheduler/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .core import start_scheduler


start_scheduler()
12 changes: 12 additions & 0 deletions burrito/apps/scheduler/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import schedule
import time

from .preprocessor.core import preprocessor_task


def start_scheduler():
schedule.every().day.at("00:30").do(preprocessor_task)

while True:
schedule.run_pending()
time.sleep(1)
Empty file.
Empty file.
Loading

0 comments on commit c7a8216

Please sign in to comment.