From dbb04b70dec1eb22ac1ee41fb253877fc0cea92b Mon Sep 17 00:00:00 2001 From: azhengzz <820108271@qq.com> Date: Tue, 6 Apr 2021 14:30:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AEstop=5Fon?= =?UTF-8?q?=5Ferror(=E8=B0=83=E5=BA=A6=E6=89=A7=E8=A1=8C=E5=8F=91=E7=94=9F?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=98=AF=E5=90=A6=E7=BB=88=E6=AD=A2=E6=89=A7?= =?UTF-8?q?=E8=A1=8C)=E7=9A=84=E5=88=A4=E6=96=AD=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ApiAutomationTest/app/cores/dispatcher.py | 18 ++++++++---------- ApiAutomationTest/app/models.py | 1 + 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ApiAutomationTest/app/cores/dispatcher.py b/ApiAutomationTest/app/cores/dispatcher.py index 2d89ba6..016200e 100644 --- a/ApiAutomationTest/app/cores/dispatcher.py +++ b/ApiAutomationTest/app/cores/dispatcher.py @@ -75,12 +75,15 @@ class AbstractDispatcher(ABC): session['project_id'] = project_id return # 下面是对参与调度的元素进行处理 + stop_on_error = True # 调度执行发生错误时终止执行 if isinstance(element, Project): self.element_type = ELEMENT_TYPE.PROJECT project_id = element.id + stop_on_error = element.project_advanced_configuration.stop_on_error elif isinstance(element, Module): self.element_type = ELEMENT_TYPE.MODULE project_id = element.project.id + stop_on_error = element.project.project_advanced_configuration.stop_on_error elif isinstance(element, Scene): self.element_type = ELEMENT_TYPE.SCENE project_id = element.module.project.id @@ -109,6 +112,7 @@ class AbstractDispatcher(ABC): self.dispatcher = Dispatcher.add(element_type=self.trigger_element_type, element_id=element.id) self.dispatcher.update_status(status=DISPATCHER_STATUS.RUNNING) self.dispatcher.end_type = DISPATCHER_END_TYPE.SUCCESS # 标识调度终止类型 + self.dispatcher.stop_on_error = stop_on_error # 调度执行发生错误时终止执行 # 实例化调度日志dispatcher_logger self.dispatcher_logger = DispatcherLogger(use_memory_string_handler=True, use_dispatcher_log_db_handler=True, @@ -119,6 +123,7 @@ class AbstractDispatcher(ABC): emit_dispatcher_start(id=self.dispatcher.id, type=self.trigger_element_type, report_id=report.id) # 调度预处理 self._dispatcher_set_up() + # 创建一条调度子数据 if self.element_type in [ELEMENT_TYPE.PROJECT, ELEMENT_TYPE.MODULE, ELEMENT_TYPE.SCENE]: # 元素类型为Project、Module、Scene时会在构造函数中直接创建调度子数据。而元素类型Case/Tool/LogicController是在Scene.execute()方法中创建 @@ -191,7 +196,7 @@ class AbstractDispatcher(ABC): else: self.dispatcher_logger.logger.error('执行异常: %s' % e) self.dispatcher_logger.logger.error(traceback.format_exc()) - if self.dispatcher_type != DISPATCHER_TYPE.DEBUG: + if self.dispatcher_type != DISPATCHER_TYPE.DEBUG and self.dispatcher.stop_on_error: self.dispatcher.update_status(status=DISPATCHER_STATUS.STOPPED) self.dispatcher.end_type = DISPATCHER_END_TYPE.ERROR # 标识调度终止类型 raise e @@ -652,9 +657,6 @@ class SceneDispatcher(AbstractSceneDispatcher): # 场景组件 self.scene = scene - # 是否发生异常时终止执行 - self.stop_on_error = self.scene.module.project.project_advanced_configuration.stop_on_error - # 标识组件执行结果 self.element_execute_result = '' @@ -677,14 +679,10 @@ class SceneDispatcher(AbstractSceneDispatcher): else: self.element_execute_result = REPORT_RESULT.ERROR # 如果配置了执行错误时不终止,则不向上抛出异常 - if self.stop_on_error: + if self.dispatcher.stop_on_error: raise e else: - # 在dispatcher.run()中发生异常会将其置为ABORT,因此这里需要重置为SUCCESS - # 表示当组件发生错误但继续执行时调度结束类型不更新(初始就是SUCCESS) - self.dispatcher.end_type = DISPATCHER_END_TYPE.SUCCESS - # 和上面同理,当继续执行时,重置调度状态为RUNNING(初始就是RUNNING) - self.dispatcher.update_status(status=DISPATCHER_STATUS.RUNNING) + pass else: pass finally: diff --git a/ApiAutomationTest/app/models.py b/ApiAutomationTest/app/models.py index a17fe59..7306612 100644 --- a/ApiAutomationTest/app/models.py +++ b/ApiAutomationTest/app/models.py @@ -3074,6 +3074,7 @@ class Dispatcher(db.Model): report = db.relationship('Report', uselist=False, back_populates='dispatcher', cascade='all') end_type = '' # 调度结束类型 DISPATCHER_END_TYPE, 暂时不需要将其作为表字段使用,而是作为实例属性使用便于在调度过程中标识 + stop_on_error = True # 调度执行发生错误时终止执行,与项目配置ProjectAdvancedConfiguration.stop_on_error一致 @classmethod def add(cls, element_type, element_id):