private async Task RestartWorkItemsAsync(UserRestartedJobMessage message, IMessageHandlerContext context) { AutomatonDatabaseContext dbContext = new AutomatonDatabaseContext(); var httpRequests = await dbContext.HttpRequestRepository.GetAllByJobIdAndStatusAsync(message.JobId, (short)WorkItemStatusType.Completed); dbContext.Commit(); var workItems = httpRequests.GroupBy(i => i.WorkItemId).Select(i => new { WorkItemId = i.Key, HttpRequests = i.ToList() }); foreach (var workItem in workItems) { var restartMessage = new UserRestartedWorkItemMessage(); restartMessage.JobId = message.JobId; restartMessage.WorkItemId = workItem.WorkItemId; restartMessage.DateActionTaken = message.DateActionTookPlace; List <UserHttpRequest> userHttpRequests = new List <UserHttpRequest>(); foreach (var httpRequest in workItem.HttpRequests) { var request = new UserHttpRequest(); if (httpRequest.AuthenticationConfigInJson != null) { request.AuthenticationConfig = JsonConvert.DeserializeObject <HttpAuthenticationConfig>(httpRequest.AuthenticationConfigInJson); } if (httpRequest.ContentHeadersInJson != null) { request.ContentHeaders = JsonConvert.DeserializeObject <Dictionary <string, string> >(httpRequest.ContentHeadersInJson); } request.ContentType = httpRequest.ContentType; request.HttpRequestId = httpRequest.Id; request.Method = httpRequest.Method; if (httpRequest.RequestHeadersInJson != null) { request.RequestHeaders = JsonConvert.DeserializeObject <Dictionary <string, string> >(httpRequest.RequestHeadersInJson); } request.Url = httpRequest.Url; request.Content = httpRequest.Content; request.UserAgent = httpRequest.UserAgent; userHttpRequests.Add(request); } restartMessage.HttpRequests = userHttpRequests; await context.SendLocal(restartMessage) ; } }
public async Task Handle(UserSubmittedHttpRequestMessage message, IMessageHandlerContext context) { AutomatonDatabaseContext dbContext = new AutomatonDatabaseContext(); await dbContext.HttpRequestRepository.UpsertAsync(new HttpRequestEntity { Id = message.HttpRequest.HttpRequestId, WorkItemId = message.WorkItemId, Url = message.HttpRequest.Url, ContentType = message.HttpRequest.ContentType, Method = message.HttpRequest.Method, Content = message.HttpRequest.Content, UserAgent = message.HttpRequest.UserAgent, RequestHeadersInJson = message.HttpRequest.RequestHeaders == null ? null : JsonConvert.SerializeObject(message.HttpRequest.RequestHeaders), ContentHeadersInJson = message.HttpRequest.ContentHeaders == null ? null : JsonConvert.SerializeObject(message.HttpRequest.ContentHeaders), AuthenticationConfigInJson = message.HttpRequest.AuthenticationConfig == null ? null : JsonConvert.SerializeObject(message.HttpRequest.AuthenticationConfig), }); await dbContext.HttpRequestStatusRepository.UpsertAsync(new HttpRequestStatusEntity { HttpRequestId = message.HttpRequest.HttpRequestId, HttpRequestStatusTypeId = (short)HttpRequestStatusType.Queued, StatusTimeStamp = DateTimeOffset.UtcNow, }); log.Info($"MESSAGE: {nameof(UserSubmittedHttpRequestMessage)}; HANDLED BY: {nameof(UserSubmittedHttpRequestHandler)}: {JsonConvert.SerializeObject(message)}"); }
private async Task SetStatusToStarted(ExecuteHttpRequestMessage message) { AutomatonDatabaseContext dbContext = new AutomatonDatabaseContext(); await dbContext.HttpRequestRepository.UpsertAsync(new HttpRequestEntity { Id = message.HttpRequest.HttpRequestId, WorkItemId = message.WorkItemId, Url = message.HttpRequest.Url, ContentType = message.HttpRequest.ContentType, Method = message.HttpRequest.Method, Content = message.HttpRequest.Content, UserAgent = message.HttpRequest.UserAgent, RequestHeadersInJson = message.HttpRequest.RequestHeaders == null ? null : JsonConvert.SerializeObject(message.HttpRequest.RequestHeaders), ContentHeadersInJson = message.HttpRequest.ContentHeaders == null ? null : JsonConvert.SerializeObject(message.HttpRequest.ContentHeaders), AuthenticationConfigInJson = message.HttpRequest.AuthenticationConfig == null ? null : JsonConvert.SerializeObject(message.HttpRequest.AuthenticationConfig), }); await dbContext.HttpRequestStatusRepository.UpsertAsync(new HttpRequestStatusEntity { HttpRequestId = message.HttpRequest.HttpRequestId, HttpRequestStatusTypeId = (short)HttpRequestStatusType.Started, StatusTimeStamp = DateTimeOffset.UtcNow, }); dbContext.Commit(); }
public async Task Handle(WorkItemCompletedMessage message, IMessageHandlerContext context) { AutomatonDatabaseContext dbContext = new AutomatonDatabaseContext(); await dbContext.WorkItemStatusRepository.UpsertAsync(new WorkItemStatusEntity { StatusTimeStamp = message.DateActionTaken, WorkItemId = message.WorkItemId, WorkItemStatusTypeId = (short)WorkItemStatusType.Completed }); dbContext.Commit(); log.Info($"MESSAGE: {nameof(WorkItemCompletedMessage)}; HANDLED BY: {nameof(WorkItemCompletedHandler)}; JID:{message.JobId}; WID:{message.WorkItemId}"); }
public async Task Handle(UserFinishedQueueingJobMessage message, IMessageHandlerContext context) { AutomatonDatabaseContext dbContext = new AutomatonDatabaseContext(); await dbContext.JobStatusRepository.UpsertAsync(new JobStatusEntity { JobId = message.JobId, JobStatusTypeId = (short)JobStatusType.FinishedQueueing, StatusTimeStamp = message.ActionTookPlaceDate, }); dbContext.Commit(); log.Info($"MESSAGE: {nameof(UserFinishedQueueingJobMessage)}; HANDLED BY: {nameof(UserFinishedQueueingJobHandler)}; JID:{message.JobId}"); }
private async Task RestartJobAsync(UserRestartedJobMessage message) { AutomatonDatabaseContext dbContext = new AutomatonDatabaseContext(); var job = await dbContext.JobRepository.GetAsync(message.JobId); await dbContext.JobStatusRepository.UpsertAsync(new JobStatusEntity { JobId = message.JobId, JobStatusTypeId = (short)JobStatusType.Restart, StatusTimeStamp = message.DateActionTookPlace }); dbContext.Commit(); }
public async Task Handle(UserCreatedJobMessage message, IMessageHandlerContext context) { AutomatonDatabaseContext dbContext = new AutomatonDatabaseContext(); await dbContext.JobRepository.UpsertAsync(new JobEntity { Id = message.JobId, JobName = message.JobName, InsertTimeStamp = message.DateActionTookPlace }); await dbContext.JobStatusRepository.UpsertAsync(new JobStatusEntity { JobId = message.JobId, JobStatusTypeId = (short)JobStatusType.Created, StatusTimeStamp = DateTimeOffset.UtcNow }); dbContext.Commit(); log.Info($"MESSAGE: {nameof(UserCreatedJobMessage)}; HANDLED BY: {nameof(UserCreatedJobHandler)}; JID:{message.JobId}"); }
public async Task Handle(WorkItemCreatedMessage message, IMessageHandlerContext context) { AutomatonDatabaseContext dbContext = new AutomatonDatabaseContext(); await dbContext.WorkItemRepository.UpsertAsync(new WorkItemEntity { Id = message.WorkItemId, JobId = message.JobId, InsertTimeStamp = message.CreateDate }); await dbContext.WorkItemStatusRepository.UpsertAsync(new WorkItemStatusEntity { WorkItemId = message.WorkItemId, WorkItemStatusTypeId = (short)WorkItemStatusType.Queued, StatusTimeStamp = message.CreateDate, }); dbContext.Commit(); log.Info($"MESSAGE: {nameof(WorkItemCreatedMessage)}; HANDLED BY: {nameof(CreateWorkItemHandler)}; JID:{message.JobId}; WID:{message.WorkItemId}"); }
private async Task SaveHttpRequestAsync(ExecuteHttpRequestMessage message, HttpResponseMessage httpResponseMessage) { AutomatonDatabaseContext dbContext = new AutomatonDatabaseContext(); var content = await httpResponseMessage.Content?.ReadAsStringAsync(); await dbContext.HttpResponseRepository.UpsertAsync(new HttpResponseEntity { Id = Guid.NewGuid(), HttpRequestId = message.HttpRequest.HttpRequestId, StatusCode = (int)httpResponseMessage.StatusCode, Body = content, InsertTimeStamp = message.CreateDate }); await dbContext.HttpRequestStatusRepository.UpsertAsync(new HttpRequestStatusEntity { HttpRequestId = message.HttpRequest.HttpRequestId, HttpRequestStatusTypeId = (short)HttpRequestStatusType.Completed, StatusTimeStamp = DateTimeOffset.UtcNow, }); dbContext.Commit(); }