MCPcopy Create free account
hub / github.com/dfinity/orbit / try_execute_request

Method try_execute_request

core/station/impl/src/services/request.rs:510–563  ·  view source on GitHub ↗
(&self, id: UUID)

Source from the content-addressed store, hash-verified

508 }
509
510 pub async fn try_execute_request(&self, id: UUID) -> Result<(), RequestExecuteError> {
511 let mut request =
512 self.get_request(&id)
513 .map_err(|e| RequestExecuteError::InternalError {
514 reason: e.to_string(),
515 })?;
516
517 if let Err(err) = request.validate() {
518 match err {
519 RequestError::ValidationError { info } => {
520 return Err(RequestExecuteError::ValidationError { info });
521 }
522 _ => {
523 let reason = format!("Unexpected validation result: {err:?}");
524 return Err(RequestExecuteError::InternalError { reason });
525 }
526 }
527 }
528
529 if !matches!(request.status, RequestStatus::Processing { .. }) {
530 let reason = format!(
531 "The request {} is not processing and thus cannot be executed.",
532 Uuid::from_bytes(id.to_owned()).hyphenated()
533 );
534 return Err(RequestExecuteError::InternalError { reason });
535 }
536
537 let executor = RequestFactory::executor(&request);
538
539 let execute_state = executor.execute().await?;
540
541 drop(executor);
542
543 let request_execution_time = next_time();
544
545 request.status = match execute_state {
546 RequestExecuteStage::Completed(_) => RequestStatus::Completed {
547 completed_at: request_execution_time,
548 },
549 RequestExecuteStage::Processing(_) => RequestStatus::Processing {
550 started_at: request_execution_time,
551 },
552 };
553
554 request.operation = match execute_state {
555 RequestExecuteStage::Completed(operation) => operation,
556 RequestExecuteStage::Processing(operation) => operation,
557 };
558
559 self.request_repository
560 .save_modified(&mut request, request_execution_time);
561
562 Ok(())
563 }
564}
565
566#[cfg(test)]

Callers 1

execute_requestMethod · 0.45

Calls 5

save_modifiedMethod · 0.80
next_timeFunction · 0.50
get_requestMethod · 0.45
validateMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected