Skip to content

Commit

Permalink
fix: 1.fix sqlalchemy session bug 2.fix email notification bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wuranxu committed Jan 3, 2024
1 parent 9a73569 commit bdb03e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/core/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,14 @@ async def notice(env: list, plan: PityTestPlan, project: Project, report_dict: d
report_dict[e]['result_color'] = '#67C23A' if report_dict[e]['plan_result'] == '通过' \
else '#E6A23C'
# 批量获取用户手机号
users = [r.get("phone") for r in users]
report_dict[e]['notification_user'] = " ".join(map(lambda x: f"@{x}", users))
ding_users = [r.get("phone") for r in users]
report_dict[e]['notification_user'] = " ".join(map(lambda x: f"@{x}", ding_users))
render_markdown = DingTalk.render_markdown(**report_dict[e], plan_name=plan.name)
if not project.dingtalk_url:
Executor.log.debug("项目未配置钉钉通知机器人")
continue
ding = DingTalk(project.dingtalk_url)
await ding.send_msg("pity测试报告", render_markdown, None, users,
await ding.send_msg("pity测试报告", render_markdown, None, ding_users,
link=report_dict[e]['report_url'])

@staticmethod
Expand Down
14 changes: 12 additions & 2 deletions app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from asyncio import current_task

from sqlalchemy import create_engine
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.ext.asyncio import AsyncSession, async_scoped_session
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Expand Down Expand Up @@ -27,7 +29,15 @@ def create_database():

# Session = sessionmaker(engine)

async_session = sessionmaker(async_engine, class_=AsyncSession)

async_session = async_scoped_session(
sessionmaker(
async_engine,
class_=AsyncSession,
expire_on_commit=False
),
scopefunc=current_task,
)

# 创建对象的基类:
Base = declarative_base()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pyjwt==2.1.0
mysql-connector-python==8.0.26
requests~=2.23.0
sqlalchemy==1.4.11
sqlalchemy==1.4.47
jsonschema
fastapi==0.75.0
uvicorn[standard]==0.17.6
Expand Down

0 comments on commit bdb03e7

Please sign in to comment.