Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/examples/cvat/exchange-oracle/src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from collections.abc import Iterable
from os import getenv
from pathlib import Path
from typing import ClassVar, Optional

from attrs.converters import to_bool
Expand All @@ -17,13 +18,26 @@
from src.utils.logging import parse_log_level
from src.utils.net import is_ipv4


def find_default_dotenv() -> Path | None:
# Check the default location in the project
dotenv_path = Path(__file__).parents[1] / ".env"
if dotenv_path.is_file():
return str(dotenv_path)
else:
return None


dotenv_path = getenv("DOTENV_PATH", None)

if dotenv_path is None:
dotenv_path = find_default_dotenv()

if dotenv_path and not os.path.exists(dotenv_path): # noqa: PTH110
raise FileNotFoundError(dotenv_path)

load_dotenv(dotenv_path)


# TODO: add some logic to report unused/deprecated env vars on startup


Expand Down
37 changes: 0 additions & 37 deletions packages/examples/cvat/recording-oracle/src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +0,0 @@
import logging

from fastapi import FastAPI

from src.core.config import Config
from src.crons import setup_cron_jobs
from src.endpoints import init_api
from src.endpoints.error_handlers import setup_error_handlers
from src.log import setup_logging

setup_logging()

app = FastAPI(
title="Human Recording Oracle",
description="""
Recording Oracle is a HUMAN oracle which main goal is to:
1. Receive webhooks from an Exchange Oracle
2. Process them and evaluate answers collected from CVAT
3. Store evaluated answers in a s3 bucket
4. Notify reputation oracle that final annotations are ready
""",
version="0.1.0",
)

init_api(app)
setup_error_handlers(app)


@app.on_event("startup")
async def startup_event():
logger = logging.getLogger("app")
logger.info("Recording Oracle is up and running!")


is_test = Config.environment == "test"
if not is_test:
setup_cron_jobs(app)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import logging

from fastapi import FastAPI

from src.core.config import Config
from src.crons import setup_cron_jobs
from src.endpoints import init_api
from src.endpoints.error_handlers import setup_error_handlers
from src.log import setup_logging

setup_logging()

app = FastAPI(
title="Human Recording Oracle",
description="""
Recording Oracle is a HUMAN oracle which main goal is to:
1. Receive webhooks from an Exchange Oracle
2. Process them and evaluate answers collected from CVAT
3. Store evaluated answers in a s3 bucket
4. Notify reputation oracle that final annotations are ready
""",
version="0.1.0",
)

init_api(app)
setup_error_handlers(app)


@app.on_event("startup")
async def startup_event():
logger = logging.getLogger("app")
logger.info("Recording Oracle is up and running!")


is_test = Config.environment == "test"
if not is_test:
setup_cron_jobs(app)
15 changes: 15 additions & 0 deletions packages/examples/cvat/recording-oracle/src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from collections.abc import Iterable
from os import getenv
from pathlib import Path
from typing import ClassVar

from attrs.converters import to_bool
Expand All @@ -16,7 +17,21 @@
from src.utils.logging import parse_log_level
from src.utils.net import is_ipv4


def find_default_dotenv() -> Path | None:
# Check the default location in the project
dotenv_path = Path(__file__).parents[1] / ".env"
if dotenv_path.is_file():
return str(dotenv_path)
else:
return None


dotenv_path = getenv("DOTENV_PATH", None)

if dotenv_path is None:
dotenv_path = find_default_dotenv()

if dotenv_path and not os.path.exists(dotenv_path): # noqa: PTH110
raise FileNotFoundError(dotenv_path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def apply_local_development_patches() -> Generator[None, None, None]:
register_in_kvstore()

uvicorn.run(
app="src:app",
app="src.apps.recording_oracle:app",
host="0.0.0.0", # noqa: S104
port=int(Config.port),
workers=Config.workers_amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
register_in_kvstore()

uvicorn.run(
app="src:app",
app="src.apps.recording_oracle:app",
host="0.0.0.0", # noqa: S104
port=int(Config.port),
workers=Config.workers_amount,
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/cvat/recording-oracle/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from sqlalchemy import inspect, text
from sqlalchemy.orm import Session

from src import app
from src.apps.recording_oracle import app
from src.db import Base, SessionLocal, engine


Expand Down