kinit/kinit-api/core/event.py
ktianc 7fbdcb3b0f 版本升级
1. 新增:微信小程序端新增微信手机号登录功能(必须为企业认证小程序)
2. 新增:加入动态更新常见问题
3. 新增:新增小程序分享功能
4. 新增:小程序新增第一次登录需要修改密码
5. 新增:新增接口权限控制
6. 新增:用户新增is_staff用来判断是否为工作人员
7. 新增:软删除新增is_delete字段来判断,delete_datetime当前主要来记录时间
8. 更新:部分接口删除功能已更新,需要试用软删除的才会试用软删除
9. 更新:更新系统配置缓存功能
10. 更新:接口认证依赖项更新
11. 更新:获取系统基础配置信息与用户协议与隐私协议更新
12. 优化:优化接口与数据库操作
2023-02-27 17:28:27 +08:00

74 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version : 1.0
# @Creaet Time : 2022/3/21 11:03
# @File : event.py
# @IDE : PyCharm
# @desc : 全局事件
from fastapi import FastAPI
from aioredis import from_url
from application.settings import REDIS_DB_URL, MONGO_DB_URL, MONGO_DB_NAME
from core.mongo import db
from utils.cache import Cache
def register_redis(app: FastAPI) -> None:
"""
把 redis 挂载到 app 对象上面
博客https://blog.csdn.net/wgPython/article/details/107668521
博客https://www.cnblogs.com/emunshe/p/15761597.html
官网https://aioredis.readthedocs.io/en/latest/getting-started/
:param app:
:return:
"""
@app.on_event('startup')
async def startup_event():
"""
获取链接
:return:
"""
print("Connecting to Redis")
app.state.redis = from_url(REDIS_DB_URL, decode_responses=True, health_check_interval=1)
await Cache(app.state.redis).cache_tab_names()
@app.on_event('shutdown')
async def shutdown_event():
"""
关闭
:return:
"""
print("Redis connection closed")
await app.state.redis.close()
def register_mongo(app: FastAPI) -> None:
"""
把 mongo 挂载到 app 对象上面
博客https://www.cnblogs.com/aduner/p/13532504.html
mongodb 官网https://www.mongodb.com/docs/drivers/motor/
motor 文档https://motor.readthedocs.io/en/stable/
:param app:
:return:
"""
@app.on_event('startup')
async def startup_event():
"""
获取 mongodb 连接
:return:
"""
await db.connect_to_database(path=MONGO_DB_URL, db_name=MONGO_DB_NAME)
@app.on_event('shutdown')
async def shutdown_event():
"""
关闭
:return:
"""
await db.close_database_connection()