public async Task <IActionResult> Result( Guid explorationId) { Exploration exploration; ExplorationStatus explorationStatus; try { exploration = explorationRegistry.GetExploration(explorationId); explorationStatus = explorationRegistry.GetStatus(explorationId); } catch (System.Collections.Generic.KeyNotFoundException) { return(NotFound($"Couldn't find exploration with id {explorationId}.")); } if (explorationStatus != ExplorationStatus.New && explorationStatus != ExplorationStatus.Processing) { try { await explorationRegistry.Remove(explorationId); } catch (TaskCanceledException) { // Do nothing, just log the occurrence. // A TaskCanceledException is expected when the client cancels an exploration. logger.LogInformation($"Exploration {explorationId} was canceled.", null); } } return(Ok(new ExploreResult(explorationId, exploration, versionInfo))); }
public async Task <IActionResult> Result( Guid explorationId) { if (!explorationRegistry.IsRegistered(explorationId)) { return(NotFound($"Couldn't find exploration with id {explorationId}.")); } var(explorationParams, exploration) = explorationRegistry.GetExploration(explorationId); var explorationStatus = exploration.Status; if (explorationStatus == ExplorationStatus.New || explorationStatus == ExplorationStatus.Validating) { return(Ok(new ExploreResult(explorationId, explorationStatus, explorationParams))); } var exploreResult = new ExploreResult(explorationId, exploration, explorationParams); if (!explorationStatus.IsComplete()) { return(Ok(exploreResult)); } // exception details are logged #pragma warning disable CA1031 // catch a more specific allowed exception type, or rethrow the exception; try { // Await the completion task to force exceptions to the surface. await exploration.Completion; } catch (TaskCanceledException) { // Do nothing, just log the occurrence. // A TaskCanceledException is expected when the client cancels an exploration. logger.LogInformation($"Exploration {explorationId} was canceled.", null); } catch (Exception) when(exploration.Completion.Exception != null) { // Log any other exceptions from the explorer and add them to the response object. logger.LogWarning($"Exceptions occurred in the exploration tasks for exploration {explorationId}."); foreach (var innerEx in exploration.Completion.Exception.Flatten().InnerExceptions) { logger.LogError(innerEx, "Exception occurred in exploration task.", innerEx.Data); exploreResult.AddErrorMessage(innerEx.Message); } } #pragma warning restore CA1031 // catch a more specific allowed exception type, or rethrow the exception; try { return(Ok(exploreResult)); } finally { explorationRegistry.Remove(explorationId); } }