Skip to content

Commit

Permalink
Add synctatic sugar to workflow/function instance
Browse files Browse the repository at this point in the history
Add method good() to the spawn request structure.
  • Loading branch information
ccicconetti committed Sep 25, 2023
1 parent cd9f565 commit 6ffaecf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
9 changes: 9 additions & 0 deletions edgeless_api/src/function_instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ pub struct SpawnFunctionResponse {
pub instance_id: Option<InstanceId>,
}

impl SpawnFunctionResponse {
pub fn good(instance_id: crate::function_instance::InstanceId) -> Self {
Self {
response_error: None,
instance_id: Some(instance_id),
}
}
}

#[derive(Debug)]
pub struct UpdateFunctionLinksRequest {
pub instance_id: Option<InstanceId>,
Expand Down
9 changes: 9 additions & 0 deletions edgeless_api/src/workflow_instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ pub struct SpawnWorkflowResponse {
pub workflow_status: Option<WorkflowInstance>,
}

impl SpawnWorkflowResponse {
pub fn good(workflow_status: WorkflowInstance) -> Self {
Self {
response_error: None,
workflow_status: Some(workflow_status),
}
}
}

#[async_trait::async_trait]
pub trait WorkflowInstanceAPI: WorkflowInstanceAPIClone + Send + Sync {
async fn start(&mut self, request: SpawnWorkflowRequest) -> anyhow::Result<SpawnWorkflowResponse>;
Expand Down
9 changes: 4 additions & 5 deletions edgeless_con/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ impl Controller {
}

active_workflows.insert(spawn_workflow_request.workflow_id.clone(), wf.clone());
match reply_sender.send(Ok(edgeless_api::workflow_instance::SpawnWorkflowResponse {
response_error: None,
workflow_status: Some(edgeless_api::workflow_instance::WorkflowInstance {
match reply_sender.send(Ok(edgeless_api::workflow_instance::SpawnWorkflowResponse::good(
edgeless_api::workflow_instance::WorkflowInstance {
workflow_id: spawn_workflow_request.workflow_id,
functions: wf
.function_instances
Expand All @@ -278,8 +277,8 @@ impl Controller {
instances: instances.clone(),
})
.collect(),
}),
})) {
},
))) {
Ok(_) => {}
Err(err) => {
log::error!("Unhandled: {:?}", err);
Expand Down
5 changes: 1 addition & 4 deletions edgeless_node/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ impl edgeless_api::function_instance::FunctionInstanceAPI for FunctionInstanceCl
}
};
match self.sender.send(AgentRequest::SPAWN(request)).await {
Ok(_) => Ok(edgeless_api::function_instance::SpawnFunctionResponse {
response_error: None,
instance_id: Some(f_id),
}),
Ok(_) => Ok(edgeless_api::function_instance::SpawnFunctionResponse::good(f_id)),
Err(err) => Err(anyhow::anyhow!(
"Agent channel error when creating a function instance: {}",
err.to_string()
Expand Down

0 comments on commit 6ffaecf

Please sign in to comment.