updated controller to use spiff step details to find correct task data to show w/ burnettk

This commit is contained in:
jasquat 2023-02-08 17:31:20 -05:00
parent ba570d0eff
commit 03d163b1e0
4 changed files with 31 additions and 16 deletions

View File

@ -18,6 +18,7 @@ depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('spiff_step_details', sa.Column('task_state', sa.String(length=50), nullable=False))
op.add_column('spiff_step_details', sa.Column('task_id', sa.String(length=50), nullable=False))
op.add_column('spiff_step_details', sa.Column('bpmn_task_identifier', sa.String(length=255), nullable=False))
op.add_column('spiff_step_details', sa.Column('engine_step_start_in_seconds', sa.DECIMAL(precision=17, scale=6), nullable=True))
@ -33,4 +34,5 @@ def downgrade():
op.drop_column('spiff_step_details', 'engine_step_start_in_seconds')
op.drop_column('spiff_step_details', 'bpmn_task_identifier')
op.drop_column('spiff_step_details', 'task_id')
op.drop_column('spiff_step_details', 'task_state')
# ### end Alembic commands ###

View File

@ -27,8 +27,9 @@ class SpiffStepDetailsModel(SpiffworkflowBaseDBModel):
)
spiff_step: int = db.Column(db.Integer, nullable=False)
task_json: dict = deferred(db.Column(db.JSON, nullable=False)) # type: ignore
task_id: str | None = db.Column(db.String(50), nullable=False)
bpmn_task_identifier: str | None = db.Column(db.String(255), nullable=False)
task_id: str = db.Column(db.String(50), nullable=False)
task_state: str = db.Column(db.String(50), nullable=False)
bpmn_task_identifier: str = db.Column(db.String(255), nullable=False)
# timestamp: float = db.Column(db.DECIMAL(17, 6), nullable=False)
engine_step_start_in_seconds: float | None = db.Column(db.DECIMAL(17, 6))

View File

@ -556,20 +556,31 @@ def process_instance_task_list(
get_task_data: bool = False,
) -> flask.wrappers.Response:
"""Process_instance_task_list."""
if spiff_step > 0:
step_detail = (
db.session.query(SpiffStepDetailsModel)
.filter(
SpiffStepDetailsModel.process_instance_id == process_instance.id,
SpiffStepDetailsModel.spiff_step == spiff_step,
)
.first()
step_detail_query = (
db.session.query(SpiffStepDetailsModel)
.filter(
SpiffStepDetailsModel.process_instance_id == process_instance.id,
)
if step_detail is not None and process_instance.bpmn_json is not None:
bpmn_json = json.loads(process_instance.bpmn_json)
bpmn_json["tasks"] = step_detail.task_json["tasks"]
bpmn_json["subprocesses"] = step_detail.task_json["subprocesses"]
process_instance.bpmn_json = json.dumps(bpmn_json)
)
if spiff_step > 0:
step_detail_query = step_detail_query.filter(SpiffStepDetailsModel.spiff_step <= spiff_step)
step_details = step_detail_query.all()
bpmn_json = json.loads(process_instance.bpmn_json)
tasks = bpmn_json['tasks']
# if step_detail is not None and process_instance.bpmn_json is not None:
for step_detail in step_details:
print(f"step_detail.task_id: {step_detail.task_id}")
print(f"step_detail.bpmn_task_identifier: {step_detail.bpmn_task_identifier}")
if step_detail.task_id in tasks:
task_data = step_detail.task_json['task_data'] | step_detail.task_json['python_env']
if task_data is None:
task_data = {}
tasks[step_detail.task_id]['data'] = task_data
process_instance.bpmn_json = json.dumps(bpmn_json)
processor = ProcessInstanceProcessor(process_instance)

View File

@ -716,7 +716,8 @@ class ProcessInstanceProcessor:
"spiff_step": self.process_instance_model.spiff_step or 1,
"task_json": task_json,
"task_id": str(spiff_task.id),
"bpmn_task_identifier": spiff_task.task_spec.id,
"task_state": spiff_task.state,
"bpmn_task_identifier": spiff_task.task_spec.name,
"engine_step_start_in_seconds": start_in_seconds,
"engine_step_end_in_seconds": end_in_seconds,
}