public async Task Execute(CancellationToken cancellationToken, EventWorker eventWorker = null) { cancellationToken.ThrowIfCancellationRequested(); DataSetup.Setup(); this.queuingConfiguration.ConfigureSystem(); var worker = await this.eventWorkerService.CreateWorker(eventWorker); // Mark any events and event locks as orphaned since we haven't started processing anything yet. await this.eventOrphanService.MarkOrphanedEventsErrored(worker); await this.logger.LogVerboseAsync( $"Starting Job Server on Event Worker Id: {worker?.Id} - Name: {worker?.Name}"); using (var server = this.kernel.Get <IJobServer>()) { await server.WaitTillProcessesAreDone(cancellationToken); await this.logger.LogVerboseAsync( $"Processes done, begin jobServer dispose on Event Worker Id: {worker?.Id} - Name: {worker?.Name}"); } await this.logger.LogVerboseAsync( $"Job Server disposed on Event Worker Id: {worker?.Id} - Name: {worker?.Name}"); await this.eventWorkerService.RemoveCurrentWorker(); await this.logger.LogVerboseAsync( $"Removed Event Worker Id: {worker?.Id} - Name: {worker?.Name}"); }
public async Task SetupWorkspaceAudits(string baseTemplateName, string primaryServerName, string username, string password, string injectAuditDataQuery, IServicesMgr servicesManager) { // Setup var testWorkspaceName = "TestWorkspaceName"; DataSetup.Setup(); // Create Workspace var workspaceId = await CreateWorkspace.CreateWorkspaceAsync(testWorkspaceName, baseTemplateName, servicesManager, username, password); // Inject Audits by running SQL script against the workspace database using (var conn = await connectionFactory.GetWorkspaceConnectionAsync(workspaceId)) { await conn.ExecuteAsync( injectAuditDataQuery, new { workspace = workspaceId, startHour = DateTime.UtcNow.AddDays(-7), endHour = DateTime.UtcNow, suggestedExecutionTime = (int?)null, usersPerHour = 3, minExecutionTime = 1000, maxExecutionTime = 10000, auditsPerHour = 1000, primaryServerName }); } }
protected override void ExecuteAgent() { try { using (var source = this.cancellationTokenSourceFactory.GetCancellationTokenSource()) { this.cancellationTokenSource = source; DataSetup.Setup(); this.ExecutePdbAgent(cancellationTokenSource.Token); } } catch (Exception ex) { string merged = $@"{this.Name} Failed.: {ex.ToString()}".Truncate(30000); this.RaiseError(merged, string.Empty); } }
protected void Application_Start(object sender, EventArgs e) { AssemblyHelper.InitResolves(); Application["ApplicationId"] = Guid.NewGuid().ToString(); RouteTable.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = System.Web.Http.RouteParameter.Optional } ).RouteHandler = new SessionRouteHandler(); AreaRegistration.RegisterAllAreas(); DataSetup.Setup(); //https://stackoverflow.com/a/20000098 AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier; }
// TODO We need to abstract this better but that can wait till next release public async Task Execute(CancellationToken cancellationToken) { await this.logger.LogVerboseAsync("Starting metric manager logic."); var executionInfo = new MetricManagerExecutionInfo(); cancellationToken.ThrowIfCancellationRequested(); // TODO: add logic to get ensure this is first manager agent DataSetup.Setup(); this.queuingConfiguration.ConfigureSystem(); await this.logger.LogVerboseAsync("Configured metric manager."); // explicitly call the first time using (executionInfo.AsMeter(e => e.InitialWork)) { using (var stopwatch = Stopwatch.StartNew().AsMeter(executionInfo, e => e.ResolveOrphanedEventLocks)) { await this.eventOrphanService.ResolveOrphanedEventLocks(); await this.logger.LogVerboseAsync( $"Completed initial resolving orphaned event locks. {stopwatch.Elapsed.TotalSeconds:N1}s"); } using (var stopwatch = Stopwatch.StartNew().AsMeter(executionInfo, e => e.ResolveTimedOutEvents)) { await this.eventOrphanService.ResolveTimedOutEvents(); await this.logger.LogVerboseAsync( $"Completed initial resolving timed out events. {stopwatch.Elapsed.TotalSeconds:N1}s"); } using (var stopwatch = Stopwatch.StartNew().AsMeter(executionInfo, e => e.CreateHourProcessingEvents)) { await this.eventSourceService.CreateHourProcessingEvents(); await this.logger.LogVerboseAsync( $"Completed creating hour processing events. {stopwatch.Elapsed.TotalSeconds:N1}s"); } using (var stopwatch = Stopwatch.StartNew().AsMeter(executionInfo, e => e.EnqueueTasksForPendingEvents)) { await this.eventSourceService.EnqueueTasksForPendingEvents(); await this.logger.LogVerboseAsync( $"Completed enqueuing task for pending events. {stopwatch.Elapsed.TotalSeconds:N1}s"); } } await this.logger.LogVerboseAsync($"Completed initial tasks: {executionInfo.ToString()}"); await this.metricManagerStatsRepository.CreateAsync(executionInfo.ToStats()); // Create timeouts var createBootstrapEventsTimeout = await this.GetTimeout(ConfigurationKeys.CreateBootstrapEventsInterval, EventConstants.DefaultCreateBootstrapEventsInterval, EventConstants.MinCreateBoostrapEventsInterval); var resolveOrphanedEventsTimeout = await this.GetTimeout(ConfigurationKeys.ResolveOrphanedEventsInterval, EventConstants.DefaultResolveOrphanedEventsInterval, EventConstants.MinResolveOrphanedEventsInterval); var enqueueTasksTimeout = await this.GetTimeout(ConfigurationKeys.EnqueueTasksInterval, EventConstants.DefaultEnqueueTasksInterval, EventConstants.MinEnqueueTasksInterval, false); var managerRunTimeout = await this.GetTimeout(ConfigurationKeys.EventManagerRunInterval, EventConstants.DefaultManagerRunInterval, EventConstants.MinManagerRunInterval); var meterReportTimeout = await this.GetTimeout(ConfigurationKeys.ManagerMeterReportTimeout, EventConstants.DefaultManagerMeterReportTimeout, EventConstants.MinManagerMeterReportTimeout); await this.logger.LogVerboseAsync($"Starting main manager loop"); using (var managerLoopMeter = executionInfo.AsMeter(e => e.ManagerMainLoops)) { while (!managerRunTimeout.IsAfterTimedOut && !cancellationToken.IsCancellationRequested) { managerLoopMeter.Increment(); if (meterReportTimeout.IsAfterTimedOut) { await this.logger.LogVerboseAsync($"Main manager loop: {executionInfo.ToString()}"); await this.metricManagerStatsRepository.CreateAsync(executionInfo.ToStats()); meterReportTimeout.Reset(); } if (createBootstrapEventsTimeout.IsAfterTimedOut) { using (executionInfo.AsMeter(e => e.CreateHourProcessingEvents)) { await this.eventSourceService.CreateHourProcessingEvents(); } createBootstrapEventsTimeout.Reset(); } if (resolveOrphanedEventsTimeout.IsAfterTimedOut) { using (executionInfo.AsMeter(e => e.ResolveOrphanedEventLocks)) { await this.eventOrphanService.ResolveOrphanedEventLocks(); } using (executionInfo.AsMeter(e => e.ResolveTimedOutEvents)) { await this.eventOrphanService.ResolveTimedOutEvents(); } resolveOrphanedEventsTimeout.Reset(); } if (enqueueTasksTimeout.IsAfterTimedOut) { using (executionInfo.AsMeter(e => e.EnqueueTasksForPendingEvents)) { await this.eventSourceService.EnqueueTasksForPendingEvents(); } enqueueTasksTimeout.Reset(); } using (executionInfo.AsMeter(e => e.CheckIfAgentIsDisabled)) { var agentExists = this.agentRepository.ReadAgentEnabled(this.agentService.AgentID); if (!agentExists) { await this.logger.LogVerboseAsync($"Read manager agent as disabled. AgentId {this.agentService.AgentID}"); break; } } var delay = new[] { createBootstrapEventsTimeout.TimeRemaining, resolveOrphanedEventsTimeout.TimeRemaining, enqueueTasksTimeout.TimeRemaining, managerRunTimeout.TimeRemaining }.Min(); executionInfo.TimeoutDelays.Increment(delay); if (delay.TotalMilliseconds > 0) { await Task.Delay(delay, cancellationToken); } } } await this.metricManagerStatsRepository.CreateAsync(executionInfo.ToStats()); await this.logger.LogVerboseAsync($"Stopping manager. {executionInfo.ToString()}"); }
public void SetUp() { connectionFactory = TestUtilities.GetIntegrationConnectionFactory(); DataSetup.Setup(); }