fix: adding new service for notification handling

This commit is contained in:
sriram veeraghanta
2024-08-02 19:46:36 +05:30
parent 76983a57e9
commit da91bf3cdc
13 changed files with 71 additions and 0 deletions

View File

0
notifier/README.md Normal file
View File

View File

@@ -0,0 +1 @@
from .home import router as home_router

View File

@@ -0,0 +1,9 @@
from fastapi import APIRouter
router = APIRouter()
@router.get("/")
def home():
return {"message": "Hello, World!"}

11
notifier/engine/app.py Normal file
View File

@@ -0,0 +1,11 @@
from fastapi import FastAPI
from .api import home_router
from .settings import settings
app = FastAPI(
title=settings.PROJECT_NAME,
description=settings.PROJECT_DESCRIPTION,
version=settings.PROJECT_VERSION,
)
app.include_router(home_router, tags=["home"])

View File

@@ -0,0 +1,4 @@
from celery import Celery
from .settings import settings
celery = Celery("tasks", broker=settings.CELERY_BROKER_URL)

View File

@@ -0,0 +1,3 @@
from common import Settings
settings = Settings()

View File

@@ -0,0 +1,10 @@
import os
class CelerySettings:
BROKER_URL = os.environ.get("CELERY_BROKER_URL", "redis://localhost:6379/0")
CELERY_ACCEPT_CONTENT = ["json"]
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_TIMEZONE = "UTC"
CELERY_ENABLE_UTC = True

View File

@@ -0,0 +1,16 @@
import os
# third-party imports
from pydantic_settings import BaseSettings
# local imports
from .celery import CelerySettings
from .postgres import PostgresSettings
class Settings(BaseSettings, CelerySettings, PostgresSettings):
PROJECT_NAME: str = "Notification Engine"
PROJECT_DESCRIPTION: str = "A simple notification service"
PROJECT_VERSION: str = "0.1.0"
SECRET_KEY: str = os.environ.get("SECRET_KEY", "123456789")
DEBUG: bool = os.environ.get("DEBUG", False)

View File

@@ -0,0 +1,9 @@
import os
class PostgresSettings:
PG_HOST: str = os.environ.get("POSTGRES_HOST", "localhost")
PG_PORT: int = os.environ.get("POSTGRES_PORT", 5432)
PG_USER: str = os.environ.get("POSTGRES_USER", "postgres")
PG_PASSWORD: str = os.environ.get("POSTGRES_PASSWORD", "postgres")
PG_NAME: str = os.environ.get("POSTGRES_DB", "notification")

View File

6
notifier/main.py Normal file
View File

@@ -0,0 +1,6 @@
from .engine.app import app
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8080)

View File

@@ -0,0 +1,2 @@
fastapi==0.111.1
pydantic==2.8.2