We have a deployment and a task to execute, we execute the task, business as usual
(
&mut self,
mut deployment: DeploymentContext,
mut task: TaskContext,
mut upstream: Box<UpstreamGatewayContext>,
)
| 409 | |
| 410 | /// We have a deployment and a task to execute, we execute the task, business as usual |
| 411 | async fn execute_deployment_task( |
| 412 | &mut self, |
| 413 | mut deployment: DeploymentContext, |
| 414 | mut task: TaskContext, |
| 415 | mut upstream: Box<UpstreamGatewayContext>, |
| 416 | ) -> (DeploymentManagerState, Option<Duration>) { |
| 417 | info!("Starting to execute deployment task"); |
| 418 | |
| 419 | loop { |
| 420 | let task_is_terminated = task.task.is_terminated(); |
| 421 | let mut await_task_termination = task.task.await_terminated(); |
| 422 | |
| 423 | tokio::select! { |
| 424 | biased; |
| 425 | |
| 426 | // If there is no task on-going for this deployment, we wait at max 15sec to receive a new one |
| 427 | _ = tokio::time::sleep(self.deadline_for_new_task), if task_is_terminated => { |
| 428 | info!("No new message after {}s, assuming deployment is terminated", self.deadline_for_new_task.as_secs()); |
| 429 | task.terminate_task().await; |
| 430 | deployment.terminate_deployment().await; |
| 431 | upstream.await_termination().await; |
| 432 | |
| 433 | return (DeploymentManagerState::SeekingNewDeployment {}, None); |
| 434 | } |
| 435 | |
| 436 | // Task is terminated, we re-loop to check if there is a new task for this deployment |
| 437 | // and to set the timeout correctly |
| 438 | _ = await_task_termination.recv(), if !task_is_terminated => { |
| 439 | info!("Engine Task terminated"); |
| 440 | } |
| 441 | |
| 442 | // We lost the connection with gateway to forward engine message, trying to reconnect |
| 443 | _ = upstream.close_upstream_tx.closed() => { |
| 444 | info!("EngineEvent forwarder to gateway has been close, trying to resume connection"); |
| 445 | let next_step = DeploymentManagerState::ResumingDeploymentTask { |
| 446 | deployment, |
| 447 | task, |
| 448 | }; |
| 449 | return (next_step, None); |
| 450 | } |
| 451 | |
| 452 | |
| 453 | // We wait to receive a new message from the gateway |
| 454 | // In case of error, we return to try to resume the current deployment. |
| 455 | // The server will let us know if the deployment is still valid |
| 456 | msg = upstream.msg_stream.next() => { |
| 457 | match msg { |
| 458 | Some(Ok(msg)) => { |
| 459 | match msg.request { |
| 460 | Some(engine_message_rx::Request::DeploymentRequest(payload)) => { |
| 461 | info!("Received new deployment task: {}", payload); |
| 462 | let new_task = (self.mk_engine_task)(payload, &deployment.deployment_info, &self.engine_client, upstream.logger(), upstream.metrics_registry(), upstream.log_file_writer().clone()); |
| 463 | match new_task { |
| 464 | Ok(new_task) => { |
| 465 | task.await_task_termination().await; |
| 466 | task = TaskContext::spawn_new_task(new_task); |
| 467 | } |
| 468 | Err(err) => { |
no test coverage detected