1 Star 0 Fork 0

Lighting/flask_vue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bbs_celery.py 939 Bytes
一键复制 编辑 原始数据 按行查看 历史
Lighting 提交于 2022-10-27 20:33 . second commit
from flask_mail import Message
from exts import mail
from celery import Celery
# 定义任务函数
def send_mail(recipient, subject, body):
message = Message(subject=subject, recipients=[recipient], body=body)
try:
mail.send(message)
return {"status": "SUCCESS"}
except Exception as e:
print(e)
return {"status": "FAILURE"}
# 创建celery对象工厂函数
def make_celery(app):
celery = Celery(app.import_name, backend=app.config['CELERY_RESULT_BACKEND'],
broker=app.config['CELERY_BROKER_URL'])
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
app.celery = celery
# 添加任务
celery.task(name="send_mail")(send_mail)
return celery
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/GoBDN/flask_vue.git
[email protected]:GoBDN/flask_vue.git
GoBDN
flask_vue
flask_vue
master

搜索帮助