Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wangwanzhong/3af7b68095659a932a52ab5f9fef9974 to your computer and use it in GitHub Desktop.
Save wangwanzhong/3af7b68095659a932a52ab5f9fef9974 to your computer and use it in GitHub Desktop.
fastapi_background_tasks.py
#! -*- coding: utf-8 -*-
import time
from fastapi import BackgroundTasks, FastAPI
app = FastAPI()
def send_email(email: str, message: str=''):
print("start send mail...")
time.sleep(5)
print("success send mail...")
@app.get('/notify/{email}')
async def notify(email: str, background_tasks: BackgroundTasks):
background_tasks.add_task(send_email, email, message='Game Start Now')
return {'status': 'success', 'email': email}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment