/// <summary> /// Starts the run /// </summary> /// <param name="run"></param> /// <param name="runRepository"></param> /// <returns></returns> private List <RunInstance> StartRun(Run run, IRunRepository runRepository) { DateTime executeStartedDateTime = DateTime.UtcNow; // Flag as scheduled run.ExecuteStartedDateTime = executeStartedDateTime; foreach (var scenario in run.Scenarios) { scenario.Status = ScenarioStatuses.Scheduled; scenario.StartedDateTime = executeStartedDateTime; // Default, may be overriden for when scenario is actually started } runRepository.Update(run); runRepository.SaveChanges(); // Persist changes before we exit lock, don't wait for HTTP request handler to call SaveChanges return(_runManager.AllScenariosStartRun(run.Id)); }
public IHttpActionResult PostCalculateAndSave(Guid runId, int?brsConfigurationTemplateId = null) { var run = _runRepository.Find(runId); if (run == null) { return(NotFound()); } var scenarioResults = _brsManager.CalculateBRSIndicators(run, brsConfigurationTemplateId); _scenarioResultRepository.UpdateRange(scenarioResults); if (brsConfigurationTemplateId.HasValue) { run.BRSConfigurationTemplateId = brsConfigurationTemplateId.Value; _runRepository.Update(run); } _scenarioResultRepository.SaveChanges(); return(Ok(_mapper.Map <List <BRSIndicatorValueForScenarioResultModel> >(scenarioResults))); }
/// <inheritdoc /> public async Task <LandmarkTriggerRunResult> TriggerRunAsync(LandmarkRunTriggerModel command, ScheduledRunSettingsModel scheduledRunSettings = null) { if (command is null) { throw new ArgumentNullException(nameof(command)); } RaiseInfo($"Starting Landmark run trigger process for ScenarioId: {command.ScenarioId}"); var run = command.ScenarioId != Guid.Empty ? _runRepository.FindByScenarioId(command.ScenarioId) : default; if (run is null) { throw new InvalidOperationException($"Run for scenario {command.ScenarioId} was not found"); } var scenario = run.Scenarios.SingleOrDefault(s => s.Id == command.ScenarioId); if (scenario is null) { throw new InvalidOperationException($"Scenario {command.ScenarioId} was not found"); } try { var request = new LandmarkBookingRequest { InputFiles = _landmarkAutoBookPayloadProvider.GetFiles(run.Id, command.ScenarioId).ToList() }; var autoBookTriggerResult = await _landmarkApi.TriggerRunAsync(request, scheduledRunSettings).ConfigureAwait(false); scenario.ExternalRunInfo = new ExternalRunInfo { ExternalRunId = autoBookTriggerResult.ProcessingId, ExternalStatus = scheduledRunSettings is null ? ExternalScenarioStatus.Accepted : ExternalScenarioStatus.Scheduled, ExternalStatusModifiedDate = _clock.GetCurrentInstant().ToDateTimeUtc(), QueueName = scheduledRunSettings?.QueueName, Priority = scheduledRunSettings?.Priority, ScheduledDateTime = scheduledRunSettings?.DateTime, Comment = scheduledRunSettings?.Comment, CreatorId = scheduledRunSettings?.CreatorId, CreatedDateTime = _clock.GetCurrentInstant().ToDateTimeUtc() }; _runRepository.Update(run); _runRepository.SaveChanges(); RaiseInfo($"Landmark run triggered for Run: {run.Id} and Scenario: {command.ScenarioId}. Processing id: {autoBookTriggerResult.ProcessingId}"); return(new LandmarkTriggerRunResult { RunId = run.Id, ExternalRunId = autoBookTriggerResult.ProcessingId, Status = scheduledRunSettings is null ? ExternalScenarioStatus.Accepted : ExternalScenarioStatus.Scheduled }); }