public async Task <DateTime> GetPickupDate(CurbsideOrder order) { var request = new PickupService.PickupRequest { For = order.For }; request.Items.AddRange(order.Items.Split(',').Select(int.Parse).ToArray()); try { _logger.LogInformation("Creating GRPC service"); var channel = GrpcChannel.ForAddress(_options.Value.Url); var client = new PickupService.PickupEstimator.PickupEstimatorClient(channel); _logger.LogInformation($"Making the GRPC call for {request.For}"); var response = await client.GetPickupTimeAsync(request); _logger.LogInformation($"Pickup time for {request.For} is {response.PickupTime.ToDateTime().ToShortDateString()}"); return(response.PickupTime.ToDateTime()); } catch (Exception e) { _logger.LogError("GRPC call has failed"); _logger.LogError(e.Message); // Gotta do real things to handle this error. return(DateTime.Now.AddYears(1)); } }
public async Task <DateTime?> GetPickupDate(CurbsideOrder order) { var request = new PickupService.PickupRequest { For = order.For }; request.Items.AddRange(order.Items.Split(',').Select(int.Parse).ToArray()); try { var channel = GrpcChannel.ForAddress(_options.Value.Url); var client = new PickupService.PickupEstimator.PickupEstimatorClient(channel); var response = await client.GetPickupTimeAsync(request); _logger.LogInformation($"Estimated a pickup date of {response.PickupTime.ToDateTime().ToShortDateString() }"); return(response.PickupTime.ToDateTime()); } catch (Exception ex) { // our plan b _logger.LogError($"Got an exception trying to get the estimated pickup for {order.Id}. Exception Details : {ex}"); return(DateTime.Now.AddDays(5)); } }
public async Task <DateTime?> GetPickupDate(CurbsideOrder order) { var request = new PickupService.PickupRequest { For = order.For, }; request.Items.AddRange(order.Items.Split(',').Select(int.Parse).ToArray()); try { var channel = GrpcChannel.ForAddress(_options.Value.Url); var client = new PickupService.PickupEstimator.PickupEstimatorClient(channel); var response = await client.GetPickupTimeAsync(request); return(response.PickupTime.ToDateTime()); } catch (Exception) { //our weak-sauce plan b. return(DateTime.Now.AddDays(5)); } }