mirror of
https://gitee.com/mao-peng/MangoTestingPlatform.git
synced 2025-12-06 11:59:15 +08:00
Compare commits
6 Commits
eb57b31100
...
c3483f75ae
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3483f75ae | ||
|
|
3ab7aad511 | ||
|
|
afe98ebb0e | ||
|
|
d9e04f58ef | ||
|
|
82431082be | ||
|
|
998765cff0 |
Binary file not shown.
@@ -37,7 +37,7 @@ class AutoSystemConfig(AppConfig):
|
||||
self.populate_time_tasks()
|
||||
self.run_tests()
|
||||
self.init_ass()
|
||||
|
||||
|
||||
# 设置定时任务调度器
|
||||
self.setup_scheduler()
|
||||
|
||||
@@ -153,8 +153,6 @@ class AutoSystemConfig(AppConfig):
|
||||
self.system_task.join()
|
||||
except AttributeError:
|
||||
pass
|
||||
# 停止全局调度器
|
||||
self.stop_scheduler()
|
||||
|
||||
def init_ass(self):
|
||||
try:
|
||||
@@ -189,7 +187,7 @@ class AutoSystemConfig(AppConfig):
|
||||
try:
|
||||
# 创建调度器实例
|
||||
self.scheduler = BackgroundScheduler()
|
||||
|
||||
|
||||
# 添加定时任务
|
||||
self.scheduler.add_job(
|
||||
self.set_case_status,
|
||||
@@ -197,10 +195,10 @@ class AutoSystemConfig(AppConfig):
|
||||
minutes=5,
|
||||
id='set_case_status'
|
||||
)
|
||||
|
||||
|
||||
# 启动调度器
|
||||
self.scheduler.start()
|
||||
|
||||
|
||||
# 注册退出时停止调度器
|
||||
atexit.register(self.stop_scheduler)
|
||||
except Exception as e:
|
||||
@@ -209,19 +207,21 @@ class AutoSystemConfig(AppConfig):
|
||||
def stop_scheduler(self):
|
||||
"""停止调度器"""
|
||||
try:
|
||||
if hasattr(self, 'scheduler') and self.scheduler:
|
||||
self.scheduler.shutdown()
|
||||
# 只有在主进程中才尝试停止调度器
|
||||
if not self._is_duplicate_process():
|
||||
if hasattr(self, 'scheduler') and self.scheduler and getattr(self.scheduler, 'running', False):
|
||||
self.scheduler.shutdown()
|
||||
log.system.info("调度器已停止")
|
||||
except Exception as e:
|
||||
log.system.error(f'停止调度器异常: {e}')
|
||||
|
||||
|
||||
def set_case_status(self):
|
||||
from django.db import transaction
|
||||
|
||||
try:
|
||||
# 确保开始时连接是干净的
|
||||
close_old_connections()
|
||||
|
||||
|
||||
from src.auto_test.auto_ui.models import UiCase, UiCaseStepsDetailed, PageSteps
|
||||
from src.auto_test.auto_pytest.models import PytestCase
|
||||
from src.auto_test.auto_api.models import ApiInfo, ApiCase, ApiCaseDetailed
|
||||
@@ -243,9 +243,9 @@ class AutoSystemConfig(AppConfig):
|
||||
status=TaskEnum.PROCEED.value,
|
||||
update_time__lt=ten_minutes_ago
|
||||
).update(status=TaskEnum.FAIL.value)
|
||||
|
||||
|
||||
# 确保事务提交
|
||||
transaction.commit()
|
||||
finally:
|
||||
# 确保结束时连接被关闭
|
||||
close_old_connections()
|
||||
close_old_connections()
|
||||
|
||||
Reference in New Issue
Block a user