|
@@ -11,6 +11,11 @@ from exceptions import *
|
|
|
from pymysql.err import OperationalError
|
|
|
import os
|
|
|
import platform
|
|
|
+from config import settings
|
|
|
+from extensions import logger
|
|
|
+from jobs import register_jobs
|
|
|
+from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
|
+from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
|
|
|
|
|
|
app = FastAPI()
|
|
|
# app.include_router(home.router)
|
|
@@ -30,6 +35,27 @@ app.add_middleware(CORSMiddleware,allow_origins=['*'],allow_credentials=False,al
|
|
|
|
|
|
app.mount('/static', StaticFiles(directory='static'), name='static')
|
|
|
|
|
|
+@app.on_event('startup')
|
|
|
+def app_startup():
|
|
|
+ logger.info('---------------------------------------')
|
|
|
+ logger.info('--------------'+ settings.ENVIRONMENT +'---------------')
|
|
|
+ logger.info('---------------------------------------')
|
|
|
+ logger.info("server started.")
|
|
|
+
|
|
|
+ sys = platform.system()
|
|
|
+ if sys == "Windows":
|
|
|
+ from warnings import filterwarnings
|
|
|
+ from pytz_deprecation_shim import PytzUsageWarning
|
|
|
+ filterwarnings('ignore', category=PytzUsageWarning)
|
|
|
+
|
|
|
+ executors = {
|
|
|
+ 'default': ThreadPoolExecutor(20),
|
|
|
+ 'processpool': ProcessPoolExecutor(5)
|
|
|
+ }
|
|
|
+ scheduler = AsyncIOScheduler(timezone='Asia/Shanghai', executors=executors)
|
|
|
+ register_jobs(scheduler)
|
|
|
+ scheduler.start()
|
|
|
+
|
|
|
# @app.exception_handler(RequestValidationError)
|
|
|
# async def validation_exception_handler(request, exc):
|
|
|
# return JSONResponse(status_code=200, content={ "errcode": 100060, "errmsg": "参数错误" }, )
|
|
@@ -76,7 +102,7 @@ if __name__ == '__main__':
|
|
|
# YzyApi.send_textcard_message(["c3o4t44nb2e1oipbs80paw"], "title", "事件进度", "https://www.baidu.com/")
|
|
|
# YzyApi.send_textcard_message(["ivj823s4b56za2jcu293f7"], "title", "事件进度", "https://www.baidu.com/")
|
|
|
# YzyApi.send_textcard_message(["ivj823s4b56za2jcu293f7"], "title", "事件进度", "https://www.baidu.com/")
|
|
|
- # YzyApi.send_textcard_message(["eb4kehgy6wj4qn0jhx1dk6"], "title", "预案名称: 茂名市自然灾害救助应急预案\n响应级别: Ⅰ级响应\n消息内容: 单位您好!《茂名市自然灾害救助应急预案》现已全面启动,特此通知您单位迅速响应,全力做好预案工作要点:负责救灾工作宣传报道协调工作。", "https://www.baidu.com/")
|
|
|
+ # YzyApi.send_textcard_message(["eb4kehgy6wj4qn0jhx1dk6"], "预案响应消息", "预案名称: 茂名市自然灾害救助应急预案\n响应级别: Ⅰ级响应\n消息内容: 单位您好!《茂名市自然灾害救助应急预案》现已全面启动,特此通知您单位迅速响应,全力做好预案工作要点:负责救灾工作宣传报道协调工作。", "https://www.baidu.com/")
|
|
|
# YzyApi.send_text_message(["eb4kehgy6wj4qn0jhx1dk6"], "事件进度")
|
|
|
|
|
|
import uvicorn
|