Skip to content

Commit

Permalink
Merge pull request #41 from DrDroidLab/enhancements/platform-ui-apis
Browse files Browse the repository at this point in the history
Enriches workflow list api with last execution details
  • Loading branch information
droid-mohit authored Apr 25, 2024
2 parents 490e0db + 39d9ff3 commit 532fe07
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 27 deletions.
24 changes: 22 additions & 2 deletions executor/workflows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ def proto(self) -> WorkflowProto:
all_actions = self.actions.filter(is_active=True)
all_action_protos = [action.proto for action in all_actions]

latest_workflow_execution = None
latest_workflow_executions = self.workflowexecution_set.order_by('-created_at')
if latest_workflow_executions:
latest_workflow_execution = latest_workflow_executions.first()

return WorkflowProto(
id=UInt64Value(value=self.id),
name=StringValue(value=self.name),
Expand All @@ -139,19 +144,34 @@ def proto(self) -> WorkflowProto:
schedule=dict_to_proto(self.schedule, WorkflowScheduleProto),
playbooks=all_ob_protos,
entry_points=all_ep_protos,
actions=all_action_protos
actions=all_action_protos,
last_execution_time=int(latest_workflow_execution.scheduled_at.replace(
tzinfo=timezone.utc).timestamp()) if latest_workflow_execution else 0,
last_execution_status=latest_workflow_execution.status if latest_workflow_execution else WorkflowExecutionStatusType.UNKNOWN_WORKFLOW_STATUS
)

@property
def proto_partial(self) -> WorkflowProto:
all_pbs = self.playbooks.filter(is_active=True)
all_ob_protos = [pb.proto_partial for pb in all_pbs]

latest_workflow_execution = None
latest_workflow_executions = self.workflowexecution_set.order_by('-created_at')
if latest_workflow_executions:
latest_workflow_execution = latest_workflow_executions.first()

return WorkflowProto(
id=UInt64Value(value=self.id),
name=StringValue(value=self.name),
description=StringValue(value=self.description),
created_by=StringValue(value=self.created_by),
created_at=int(self.created_at.replace(tzinfo=timezone.utc).timestamp()),
is_active=BoolValue(value=self.is_active),
schedule=dict_to_proto(self.schedule, WorkflowScheduleProto)
playbooks=all_ob_protos,
schedule=dict_to_proto(self.schedule, WorkflowScheduleProto),
last_execution_time=int(latest_workflow_execution.scheduled_at.replace(
tzinfo=timezone.utc).timestamp()) if latest_workflow_execution else 0,
last_execution_status=latest_workflow_execution.status if latest_workflow_execution else WorkflowExecutionStatusType.UNKNOWN_WORKFLOW_STATUS
)


Expand Down
3 changes: 3 additions & 0 deletions protos/playbooks/workflow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ message Workflow {
repeated Playbook playbooks = 8;
repeated WorkflowEntryPoint entry_points = 9;
repeated WorkflowAction actions = 10;

sfixed64 last_execution_time = 11;
WorkflowExecutionStatusType last_execution_status = 12;
}


Expand Down
Loading

0 comments on commit 532fe07

Please sign in to comment.