Skip to content

Commit

Permalink
Merge pull request #155 from hoomano/kroussel/workflow_refacto
Browse files Browse the repository at this point in the history
Kroussel/workflow refacto
  • Loading branch information
xbasset authored Jul 1, 2024
2 parents 5c7c888 + d7b6a3d commit e512207
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
8 changes: 1 addition & 7 deletions backend/app/models/workflows/workflow_process_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,12 @@ def end_workflow_execution(self):

def _generate_produced_text(self):
try:
# For now, production of a workflow is the concatenation of results of all last step's validated executions' results
last_step = self.workflow_execution.task.steps[-1]
validated_last_step_executions = self.workflow_execution.get_valid_executions_of_a_step(last_step.workflow_step_pk)

production = "\n\n".join([list(step.result[0].values())[0] for step in validated_last_step_executions])

produced_text_manager = TaskProducedTextManager(self.workflow_execution.session_id,
self.workflow_execution.user.user_id,
self.workflow_execution.user_task_execution_pk,
self.workflow_execution.task.name_for_system)
produced_text_pk, produced_text_version_pk, title, production, text_type = produced_text_manager.save_produced_text(
production, title="", text_type_pk=self.workflow_execution.task.output_text_type_fk)
self.workflow_execution.result, title="", text_type_pk=self.workflow_execution.task.output_text_type_fk)

return produced_text_pk, produced_text_version_pk, title, production

Expand Down
15 changes: 14 additions & 1 deletion mojodex_core/entities/user_workflow_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,17 @@ def get_valid_executions_of_a_step(self,workflow_step_pk):
.order_by(UserWorkflowStepExecution.creation_date.asc()) \
.all()
except Exception as e:
raise Exception(f"{self.__class__.__name__} :: get_valid_executions_of_a_step :: {e}")
raise Exception(f"{self.__class__.__name__} :: get_valid_executions_of_a_step :: {e}")


@property
def result(self):
"""
For now, result of a workflow is the concatenation of results of all last step's validated executions' results
"""
try:
last_step = self.task.steps[-1]
validated_last_step_executions = self.get_valid_executions_of_a_step(last_step.workflow_step_pk)
return "\n\n".join([list(step.result[0].values())[0] for step in validated_last_step_executions])
except Exception as e:
raise Exception(f"{self.__class__.__name__} :: result :: {e}")
23 changes: 13 additions & 10 deletions mojodex_core/entities/workflow_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,33 @@ def get_definition_in_language(self, language_code):
raise Exception(f"{self.__class__.__name__} :: get_definition_in_language :: {e}")


@property
def dependency_step(self):
"""The dependency step of a workflow step is the step of its workflow which rank is the previous one."""
def _get_relative_step_by_rank(self, relative_rank: int):
"""
Get the relative step of a workflow step by its rank."""
try:
session = object_session(self)
return session.query(MdWorkflowStep) \
.filter(MdWorkflowStep.task_fk == self.task_fk) \
.filter(MdWorkflowStep.rank == self.rank - 1) \
.filter(MdWorkflowStep.rank == self.rank + relative_rank) \
.first()
except Exception as e:
raise Exception(f"{self.__class__.__name__} :: _get_relative_step_by_rank :: {e}")

@property
def dependency_step(self):
"""The dependency step of a workflow step is the step of its workflow which rank is the previous one."""
try:
return self._get_relative_step_by_rank(-1)
except Exception as e:
raise Exception(f"{self.__class__.__name__} :: dependency_step :: {e}")

@property
def next_step(self):
"""
The next step of a workflow step is the step of its workflow which rank is the next one.
:return:
"""
try:
session = object_session(self)
return session.query(MdWorkflowStep) \
.filter(MdWorkflowStep.task_fk == self.task_fk) \
.filter(MdWorkflowStep.rank == self.rank + 1) \
.first()
return self._get_relative_step_by_rank(+1)
except Exception as e:
raise Exception(f"{self.__class__.__name__} :: next_step :: {e}")

Expand Down

0 comments on commit e512207

Please sign in to comment.