示例#1
0
        /// <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));
        }
示例#2
0
        /// <summary>
        /// Creates run from template
        /// </summary>
        /// <param name="templateRun"></param>
        /// <param name="runRepository"></param>
        /// <returns></returns>
        private Run CreateRunFromTemplate(Run templateRun, IRunRepository runRepository)
        {
            using (var scope = _repositoryFactory.BeginRepositoryScope())
            {
                // Get sales areas for the run
                var salesAreaRepository = scope.CreateRepository <ISalesAreaRepository>();

                var salesAreas = RunManager.GetSalesAreas(templateRun, salesAreaRepository.GetAll());

                // Set the default run start date time using today's date and time from template run, use it as the starting point to try and
                // find some schedule data.
                DateTime startingDateTime = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, templateRun.StartDate.Hour, templateRun.StartDate.Minute, templateRun.StartDate.Second, templateRun.StartDate.Millisecond, templateRun.StartDate.Kind);

                // Clone template run, reset it, set date range
                Run cloneRun = (Run)templateRun.Clone();
                cloneRun.Id                     = Guid.NewGuid();
                cloneRun.Description            = $"Deployment Test ({GetVersion().Version})";
                cloneRun.CreatedDateTime        = DateTime.UtcNow;
                cloneRun.ExecuteStartedDateTime = null;
                cloneRun.LastModifiedDateTime   = cloneRun.CreatedDateTime;
                cloneRun.IsLocked               = false;
                cloneRun.Scenarios.ForEach(scenario => scenario.ResetToPendingStatus());
                cloneRun.StartDate = GetRunStartDate(startingDateTime, salesAreas, 90);
                if (cloneRun.StartDate == DateTime.MaxValue)
                {
                    throw new Exception("Unable to determine start date for test run due to insufficient data");
                }
                cloneRun.EndDate = cloneRun.StartDate.AddDays(1);
                cloneRun.Real    = false;  // Flag that it's not a real run

                // Clear IDs so that we can assign new ones
                //IdUpdater.ClearIds(cloneRun);
                cloneRun.Id       = Guid.Empty;
                cloneRun.CustomId = 0;

                // Set new IDs
                IdUpdater.SetIds(cloneRun, _identityGeneratorResolver);

                // Save run
                runRepository.Add(cloneRun);
                runRepository.SaveChanges();
                return(cloneRun);
            }
        }
示例#3
0
        /// <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
                });
            }