public void OnPerforming(PerformingContext context) { if (context is null) { _logger.Error("Failed to perform jobPerformingContext is null"); return; } }
public Task <ConsumerResult> Consume(byte[] body, object parameters) { var headers = parameters as Headers; if (!headers.KeyExists("Warewolf-Execution-Id")) { headers["Warewolf-Execution-Id"] = new[] { Guid.NewGuid().ToString() }; } var empty = new string[] { }; var executionId = Guid.Parse(headers["Warewolf-Execution-Id"].FirstOrDefault()); var customTransactionID = headers["Warewolf-Custom-Transaction-Id", empty].FirstOrDefault(); string strBody = System.Text.Encoding.UTF8.GetString(body); _logger.StartExecution($"[{executionId}] - {customTransactionID} processing body {strBody} "); var startDate = DateTime.UtcNow; Task <ConsumerResult> task = null; try { task = _consumer.Consume(body, parameters); task.Wait(); var endDate = DateTime.UtcNow; var duration = endDate - startDate; if (task.Result == ConsumerResult.Success) { _logger.Info($"[{executionId}] - {customTransactionID} success processing body {strBody}"); var executionInfo = new ExecutionInfo(startDate, duration, endDate, Warewolf.Triggers.QueueRunStatus.Success, executionId, customTransactionID); var executionEntry = new ExecutionHistory(_resourceId, "", executionInfo, _userName); _logger.ExecutionSucceeded(executionEntry); } else { _logger.Error($"Failed to execute {_resourceId + " [" + executionId + "] " + strBody}"); CreateExecutionError(task, executionId, startDate, endDate, duration, customTransactionID); } return(Task.Run(() => ConsumerResult.Success)); } catch (Exception) { var endDate = DateTime.UtcNow; var duration = endDate - startDate; _logger.Warn($"[{executionId}] - {customTransactionID} failure processing body {strBody}"); CreateExecutionError(task, executionId, startDate, endDate, duration, customTransactionID); return(Task.Run(() => ConsumerResult.Failed)); } }
public Task <ConsumerResult> Consume(byte[] body) { var executionId = Guid.NewGuid(); string strBody = System.Text.Encoding.UTF8.GetString(body); _logger.StartExecution($"processing body {strBody}"); var startDate = DateTime.UtcNow; var task = _consumer.Consume(body); task.ContinueWith((requestForwarderResult) => { var endDate = DateTime.UtcNow; var duration = endDate - startDate; _logger.Warn($"failure processing body {strBody}"); CreateExecutionError(requestForwarderResult, executionId, startDate, endDate, duration); }, TaskContinuationOptions.OnlyOnFaulted); task.ContinueWith((requestForwarderResult) => { var endDate = DateTime.UtcNow; var duration = endDate - startDate; if (requestForwarderResult.Result == ConsumerResult.Success) { _logger.Info($"success processing body {strBody}"); var executionInfo = new ExecutionInfo(startDate, duration, endDate, Warewolf.Triggers.QueueRunStatus.Success, executionId); var executionEntry = new ExecutionHistory(_resourceId, "", executionInfo, _userName); _logger.ExecutionSucceeded(executionEntry); } else { _logger.Error($"Failed to execute {_resourceId + " " + strBody}"); CreateExecutionError(requestForwarderResult, executionId, startDate, endDate, duration); } }, TaskContinuationOptions.OnlyOnRanToCompletion); if (task.IsFaulted) { return(Task.Run(() => ConsumerResult.Failed)); } else { return(Task.Run(() => ConsumerResult.Success)); } }
public void OnPerformResume(PerformingContext context) { var jobArg = context.BackgroundJob.Job.Args[0]; var backgroundJobId = context.BackgroundJob.Id; var resumptionFactory = _resumptionFactory ?? new ResumptionFactory(); var resumption = resumptionFactory.New(); if (resumption.Connect()) { var values = jobArg as Dictionary <string, StringBuilder>; LogResumption(values); var result = resumption.Resume(values); if (result.HasError) { throw new InvalidOperationException(result.Message?.ToString(), new Exception(result.Message?.ToString())); } } else { _logger.Error("Failed to perform job {0}, could not establish a connection.", backgroundJobId); } }