Merge pull request #437 from sartography/waiting-workflow-errors-566

Waiting workflow errors #566
This commit is contained in:
Dan Funk 2021-12-13 13:07:07 -05:00 committed by GitHub
commit be96497051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 1 deletions

View File

@ -86,6 +86,7 @@ class WorkflowStatus(enum.Enum):
user_input_required = "user_input_required"
waiting = "waiting"
complete = "complete"
erroring = "erroring"
class WorkflowSpecDependencyFile(db.Model):

View File

@ -111,6 +111,7 @@ class WorkflowService(object):
processor.bpmn_workflow.do_engine_steps()
processor.save()
except Exception as e:
workflow_model.status = WorkflowStatus.erroring
app.logger.error(f"Error running waiting task for workflow #%i (%s) for study #%i. %s" %
(workflow_model.id,
workflow_model.workflow_spec.id,

View File

@ -0,0 +1,28 @@
"""new workflow status
Revision ID: 44dd9397c555
Revises: d830959e96c0
Create Date: 2021-12-09 14:03:45.526308
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '44dd9397c555'
down_revision = 'd830959e96c0'
branch_labels = None
depends_on = None
def upgrade():
op.execute("ALTER TYPE WorkflowStatus ADD VALUE 'erroring'")
def downgrade():
op.execute("UPDATE workflow set status='waiting' WHERE status = 'erroring'")
op.execute('ALTER TYPE WorkflowStatus RENAME TO ws_old;')
op.execute("CREATE TYPE WorkflowStatus AS ENUM('not_started', 'user_input_required', 'waiting', 'complete')")
op.execute("ALTER TABLE workflow ALTER COLUMN status TYPE workflowstatus USING status::text::workflowstatus;")
op.execute('DROP TYPE ws_old;')

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0txh0df" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<bpmn:process id="Process_RaiseError" name="Raise Error" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_0wi12bb</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0wi12bb" sourceRef="StartEvent_1" targetRef="Activity_RaiseError" />
<bpmn:scriptTask id="Activity_RaiseError" name="Raise Error">
<bpmn:incoming>Flow_0wi12bb</bpmn:incoming>
<bpmn:outgoing>Flow_1o3s2q3</bpmn:outgoing>
<bpmn:script>failing_script()</bpmn:script>
</bpmn:scriptTask>
<bpmn:endEvent id="Event_1w5ty7j">
<bpmn:incoming>Flow_1o3s2q3</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1o3s2q3" sourceRef="Activity_RaiseError" targetRef="Event_1w5ty7j" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_RaiseError">
<bpmndi:BPMNEdge id="Flow_0wi12bb_di" bpmnElement="Flow_0wi12bb">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1o3s2q3_di" bpmnElement="Flow_1o3s2q3">
<di:waypoint x="370" y="117" />
<di:waypoint x="432" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1f79clc_di" bpmnElement="Activity_RaiseError">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1w5ty7j_di" bpmnElement="Event_1w5ty7j">
<dc:Bounds x="432" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -43,4 +43,4 @@ class TestTimerEvent(BaseTest):
self.assertRegex(cm.output[0], f"workflow #%i" % workflow.id)
self.assertRegex(cm.output[0], f"study #%i" % workflow.study_id)
self.assertTrue(wf.status == WorkflowStatus.waiting)
self.assertTrue(wf.status == WorkflowStatus.erroring)

View File

@ -0,0 +1,21 @@
from tests.base_test import BaseTest
from crc import session
from crc.models.workflow import WorkflowModel, WorkflowStatus
from crc.services.workflow_service import WorkflowService
class TestWaitingTaskError(BaseTest):
def test_waiting_task_error(self):
workflow = self.create_workflow('raise_error')
workflow.status = WorkflowStatus.waiting
session.commit()
status_before = session.query(WorkflowModel.status).filter(WorkflowModel.id == workflow.id).scalar()
WorkflowService.do_waiting()
status_after = session.query(WorkflowModel.status).filter(WorkflowModel.id == workflow.id).scalar()
self.assertEqual('waiting', status_before.value)
self.assertEqual('erroring', status_after.value)