committed by
GitHub
16 changed files with 66 additions and 56 deletions
@ -1,15 +1,19 @@ |
|||||
|
from typing import Dict |
||||
|
|
||||
from fastapi import BackgroundTasks, FastAPI |
from fastapi import BackgroundTasks, FastAPI |
||||
|
|
||||
app = FastAPI() |
app = FastAPI() |
||||
|
|
||||
|
|
||||
def write_notification(email: str, message=""): |
def write_notification(email: str, message: str = "") -> None: |
||||
with open("log.txt", mode="w") as email_file: |
with open("log.txt", mode="w") as email_file: |
||||
content = f"notification for {email}: {message}" |
content = f"notification for {email}: {message}" |
||||
email_file.write(content) |
email_file.write(content) |
||||
|
|
||||
|
|
||||
@app.post("/send-notification/{email}") |
@app.post("/send-notification/{email}") |
||||
async def send_notification(email: str, background_tasks: BackgroundTasks): |
async def send_notification( |
||||
|
email: str, background_tasks: BackgroundTasks |
||||
|
) -> Dict[str, str]: |
||||
background_tasks.add_task(write_notification, email, message="some notification") |
background_tasks.add_task(write_notification, email, message="some notification") |
||||
return {"message": "Notification sent in the background"} |
return {"message": "Notification sent in the background"} |
||||
|
Loading…
Reference in new issue