Created
July 21, 2020 06:12
-
-
Save wangwanzhong/3af7b68095659a932a52ab5f9fef9974 to your computer and use it in GitHub Desktop.
fastapi_background_tasks.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! -*- 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