public async Task <ActionResult> CallElevator(TripRequest trip) { try { int response = await _callPanelService.CallElevator(trip); return(Ok(response)); } catch (Exception e) { _logger.LogError(e, $"Error from CallPanelService.CallElevator - origin: {trip.origin} \tdestination: {trip.destination}"); return(StatusCode(503)); } }
private void SimulateElevatorCalls() { var rand = new Random(); var retries = 0; var minDelay = _callPanelConfiguration.MinDelayBetweenSimulatedCalls; var maxDelay = _callPanelConfiguration.MaxDelayBetweenSimulatedCalls; while (true) { var tripRequest = new TripRequest(); tripRequest.origin = rand.Next(_buildingConfiguration.FloorCount) + 1; do { tripRequest.destination = rand.Next(_buildingConfiguration.FloorCount) + 1; } while (tripRequest.origin == tripRequest.destination); _logger.LogInformation($"Simulating new elevator call - origin: {tripRequest.origin} \tdestination:{tripRequest.destination}"); try { _callPanelService.CallElevator(tripRequest).Wait(); Thread.Sleep(rand.Next(minDelay, maxDelay) * 1000); } catch (Exception ex) { _logger.LogError(ex.ToString()); if (retries++ > 1) { _logger.LogInformation("Too many timeouts, stopping"); break; } _logger.LogInformation("Retrying in 60 seconds..."); Thread.Sleep(6000); } } }