Skip to content

Commit afc9928

Browse files
insistencegitee-org
authored andcommitted
!32 Dash-FastAPI-Admin v2.1.1
Merge pull request !32 from insistence/develop
2 parents bafc3cb + 5c46eb3 commit afc9928

File tree

11 files changed

+57
-41
lines changed

11 files changed

+57
-41
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<p align="center">
22
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png">
33
</p>
4-
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v2.1.0</h1>
4+
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v2.1.1</h1>
55
<h4 align="center">基于Dash+FastAPI前后端分离的纯Python快速开发框架</h4>
66
<p align="center">
77
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/stargazers"><img src="https://gitee.com/insistence2022/dash-fastapi-admin/badge/star.svg?theme=dark"></a>
88
<a href="https://github.com/insistence/Dash-FastAPI-Admin"><img src="https://img.shields.io/github/stars/insistence/Dash-FastAPI-Admin?style=social"></a>
9-
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v2.1.0-brightgreen.svg"></a>
9+
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v2.1.1-brightgreen.svg"></a>
1010
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
1111
<img src="https://img.shields.io/badge/python-≥3.9-blue">
1212
<img src="https://img.shields.io/badge/MySQL-≥5.7-blue">

dash-fastapi-backend/.env.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '2.1.0'
13+
APP_VERSION= '2.1.1'
1414
# 应用是否开启热重载
1515
APP_RELOAD = true
1616
# 应用是否开启IP归属区域查询

dash-fastapi-backend/.env.prod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '2.1.0'
13+
APP_VERSION= '2.1.1'
1414
# 应用是否开启热重载
1515
APP_RELOAD = false
1616
# 应用是否开启IP归属区域查询

dash-fastapi-backend/config/get_scheduler.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import json
22
from apscheduler.events import EVENT_ALL
3-
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
4-
from apscheduler.schedulers.background import BackgroundScheduler
3+
from apscheduler.executors.asyncio import AsyncIOExecutor
4+
from apscheduler.executors.pool import ProcessPoolExecutor
55
from apscheduler.jobstores.memory import MemoryJobStore
66
from apscheduler.jobstores.redis import RedisJobStore
77
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
8+
from apscheduler.schedulers.asyncio import AsyncIOScheduler
89
from apscheduler.triggers.cron import CronTrigger
10+
from asyncio import iscoroutinefunction
911
from datetime import datetime, timedelta
1012
from sqlalchemy.engine import create_engine
1113
from sqlalchemy.orm import sessionmaker
@@ -109,9 +111,9 @@ def __find_recent_workday(cls, day: int):
109111
)
110112
),
111113
}
112-
executors = {'default': ThreadPoolExecutor(20), 'processpool': ProcessPoolExecutor(5)}
114+
executors = {'default': AsyncIOExecutor(), 'processpool': ProcessPoolExecutor(5)}
113115
job_defaults = {'coalesce': False, 'max_instance': 1}
114-
scheduler = BackgroundScheduler()
116+
scheduler = AsyncIOScheduler()
115117
scheduler.configure(jobstores=job_stores, executors=executors, job_defaults=job_defaults)
116118

117119

@@ -132,9 +134,7 @@ async def init_system_scheduler(cls):
132134
async with AsyncSessionLocal() as session:
133135
job_list = await JobDao.get_job_list_for_scheduler(session)
134136
for item in job_list:
135-
query_job = cls.get_scheduler_job(job_id=str(item.job_id))
136-
if query_job:
137-
cls.remove_scheduler_job(job_id=str(item.job_id))
137+
cls.remove_scheduler_job(job_id=str(item.job_id))
138138
cls.add_scheduler_job(item)
139139
scheduler.add_listener(cls.scheduler_event_listener, EVENT_ALL)
140140
logger.info('系统初始定时任务加载成功')
@@ -169,6 +169,10 @@ def add_scheduler_job(cls, job_info: JobModel):
169169
:param job_info: 任务对象信息
170170
:return:
171171
"""
172+
job_func = eval(job_info.invoke_target)
173+
job_executor = job_info.job_executor
174+
if iscoroutinefunction(job_func):
175+
job_executor = 'default'
172176
scheduler.add_job(
173177
func=eval(job_info.invoke_target),
174178
trigger=MyCronTrigger.from_crontab(job_info.cron_expression),
@@ -180,7 +184,7 @@ def add_scheduler_job(cls, job_info: JobModel):
180184
coalesce=True if job_info.misfire_policy == '2' else False,
181185
max_instances=3 if job_info.concurrent == '0' else 1,
182186
jobstore=job_info.job_group,
183-
executor=job_info.job_executor,
187+
executor=job_executor,
184188
)
185189

186190
@classmethod
@@ -191,6 +195,10 @@ def execute_scheduler_job_once(cls, job_info: JobModel):
191195
:param job_info: 任务对象信息
192196
:return:
193197
"""
198+
job_func = eval(job_info.invoke_target)
199+
job_executor = job_info.job_executor
200+
if iscoroutinefunction(job_func):
201+
job_executor = 'default'
194202
scheduler.add_job(
195203
func=eval(job_info.invoke_target),
196204
trigger='date',
@@ -203,7 +211,7 @@ def execute_scheduler_job_once(cls, job_info: JobModel):
203211
coalesce=True if job_info.misfire_policy == '2' else False,
204212
max_instances=3 if job_info.concurrent == '0' else 1,
205213
jobstore=job_info.job_group,
206-
executor=job_info.job_executor,
214+
executor=job_executor,
207215
)
208216

209217
@classmethod
@@ -214,7 +222,9 @@ def remove_scheduler_job(cls, job_id: Union[str, int]):
214222
:param job_id: 任务id
215223
:return:
216224
"""
217-
scheduler.remove_job(job_id=str(job_id))
225+
query_job = cls.get_scheduler_job(job_id=job_id)
226+
if query_job:
227+
scheduler.remove_job(job_id=str(job_id))
218228

219229
@classmethod
220230
def scheduler_event_listener(cls, event):

dash-fastapi-backend/module_admin/service/job_service.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ async def edit_job_services(cls, query_db: AsyncSession, page_object: EditJobMod
129129
raise ServiceException(message=f'修改定时任务{page_object.job_name}失败,定时任务已存在')
130130
try:
131131
await JobDao.edit_job_dao(query_db, edit_job)
132-
query_job = SchedulerUtil.get_scheduler_job(job_id=edit_job.get('job_id'))
133-
if query_job:
134-
SchedulerUtil.remove_scheduler_job(job_id=edit_job.get('job_id'))
132+
SchedulerUtil.remove_scheduler_job(job_id=edit_job.get('job_id'))
135133
if edit_job.get('status') == '0':
136134
job_info = await cls.job_detail_services(query_db, edit_job.get('job_id'))
137135
SchedulerUtil.add_scheduler_job(job_info=job_info)
@@ -152,9 +150,7 @@ async def execute_job_once_services(cls, query_db: AsyncSession, page_object: Jo
152150
:param page_object: 定时任务对象
153151
:return: 执行一次定时任务结果
154152
"""
155-
query_job = SchedulerUtil.get_scheduler_job(job_id=page_object.job_id)
156-
if query_job:
157-
SchedulerUtil.remove_scheduler_job(job_id=page_object.job_id)
153+
SchedulerUtil.remove_scheduler_job(job_id=page_object.job_id)
158154
job_info = await cls.job_detail_services(query_db, page_object.job_id)
159155
if job_info:
160156
SchedulerUtil.execute_scheduler_job_once(job_info=job_info)
@@ -176,9 +172,7 @@ async def delete_job_services(cls, query_db: AsyncSession, page_object: DeleteJo
176172
try:
177173
for job_id in job_id_list:
178174
await JobDao.delete_job_dao(query_db, JobModel(job_id=job_id))
179-
query_job = SchedulerUtil.get_scheduler_job(job_id=job_id)
180-
if query_job:
181-
SchedulerUtil.remove_scheduler_job(job_id=job_id)
175+
SchedulerUtil.remove_scheduler_job(job_id=job_id)
182176
await query_db.commit()
183177
return CrudResponseModel(is_success=True, message='删除成功')
184178
except Exception as e:

dash-fastapi-backend/module_admin/service/menu_service.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ async def add_menu_services(cls, query_db: AsyncSession, page_object: MenuModel)
9999
:return: 新增菜单校验结果
100100
"""
101101
if not await cls.check_menu_name_unique_services(query_db, page_object):
102-
raise ServiceException(message=f'新增菜单{page_object.post_name}失败,菜单名称已存在')
102+
raise ServiceException(message=f'新增菜单{page_object.menu_name}失败,菜单名称已存在')
103103
elif page_object.is_frame == MenuConstant.YES_FRAME and not StringUtil.is_http(page_object.path):
104-
raise ServiceException(message=f'新增菜单{page_object.post_name}失败,地址必须以http(s)://开头')
104+
raise ServiceException(message=f'新增菜单{page_object.menu_name}失败,地址必须以http(s)://开头')
105105
else:
106106
try:
107107
await MenuDao.add_menu_dao(query_db, page_object)
@@ -124,11 +124,11 @@ async def edit_menu_services(cls, query_db: AsyncSession, page_object: MenuModel
124124
menu_info = await cls.menu_detail_services(query_db, page_object.menu_id)
125125
if menu_info.menu_id:
126126
if not await cls.check_menu_name_unique_services(query_db, page_object):
127-
raise ServiceException(message=f'修改菜单{page_object.post_name}失败,菜单名称已存在')
127+
raise ServiceException(message=f'修改菜单{page_object.menu_name}失败,菜单名称已存在')
128128
elif page_object.is_frame == MenuConstant.YES_FRAME and not StringUtil.is_http(page_object.path):
129-
raise ServiceException(message=f'修改菜单{page_object.post_name}失败,地址必须以http(s)://开头')
129+
raise ServiceException(message=f'修改菜单{page_object.menu_name}失败,地址必须以http(s)://开头')
130130
elif page_object.menu_id == page_object.parent_id:
131-
raise ServiceException(message=f'修改菜单{page_object.post_name}失败,上级菜单不能选择自己')
131+
raise ServiceException(message=f'修改菜单{page_object.menu_name}失败,上级菜单不能选择自己')
132132
else:
133133
try:
134134
await MenuDao.edit_menu_dao(query_db, edit_menu)

dash-fastapi-backend/module_task/scheduler_test.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33

44
def job(*args, **kwargs):
5+
"""
6+
定时任务执行同步函数示例
7+
"""
58
print(args)
69
print(kwargs)
7-
print(f'{datetime.now()}执行了')
10+
print(f'{datetime.now()}同步函数执行了')
11+
12+
13+
async def async_job(*args, **kwargs):
14+
"""
15+
定时任务执行异步函数示例
16+
"""
17+
print(args)
18+
print(kwargs)
19+
print(f'{datetime.now()}异步函数执行了')

dash-fastapi-frontend/.env.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ APP_HOST = '0.0.0.0'
1616
# 应用端口
1717
APP_PORT = 8088
1818
# 应用版本
19-
APP_VERSION= '2.1.0'
19+
APP_VERSION= '2.1.1'
2020
# 应用是否开启debug模式
2121
APP_DEBUG = true
2222
# flask-compress压缩配置

dash-fastapi-frontend/.env.prod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ APP_HOST = '0.0.0.0'
1616
# 应用端口
1717
APP_PORT = 8088
1818
# 应用版本
19-
APP_VERSION= '2.1.0'
19+
APP_VERSION= '2.1.1'
2020
# 应用是否开启debug模式
2121
APP_DEBUG = false
2222
# flask-compress压缩配置

requirements-pg.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
APScheduler==3.10.4
22
asyncpg==0.30.0
3-
cachebox==4.1.2
4-
dash==2.18.1
3+
cachebox==4.2.3
4+
dash==2.18.2
55
DateTime==5.5
66
fastapi[all]==0.115.0
77
feffery-antd-charts==0.1.0rc5
8-
feffery-antd-components==0.3.8
8+
feffery-antd-components==0.3.10
99
feffery-markdown-components==0.2.10
1010
feffery-utils-components==0.2.0rc24
1111
Flask-Compress==1.15
@@ -16,11 +16,11 @@ pandas==2.2.2
1616
passlib[bcrypt]==1.7.4
1717
Pillow==10.4.0
1818
psutil==6.0.0
19-
pydantic-validation-decorator==0.1.2
19+
pydantic-validation-decorator==0.1.4
2020
PyJWT[crypto]==2.8.0
2121
psycopg2==2.9.10
2222
redis==5.0.7
2323
requests==2.32.3
2424
SQLAlchemy[asyncio]==2.0.31
2525
user-agents==2.2.0
26-
waitress==3.0.0
26+
waitress==3.0.1

0 commit comments

Comments
 (0)