示例#1
0
        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));
            }
        }
示例#2
0
        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}");
                var executionInfo        = new ExecutionInfo(startDate, duration, endDate, Warewolf.Triggers.QueueRunStatus.Error, executionId);
                var executionEntry       = new ExecutionHistory(_resourceId, "", executionInfo, _userName);
                executionEntry.Exception = requestForwarderResult.Exception;

                _logger.ExecutionFailed(executionEntry);
            }, 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);
                }
            }, TaskContinuationOptions.OnlyOnRanToCompletion);

            if (task.IsFaulted)
            {
                return(Task.Run(() => ConsumerResult.Failed));
            }
            else
            {
                return(Task.Run(() => ConsumerResult.Success));
            }
        }
示例#3
0
        protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            var allErrors = new ErrorResultTO();

            Response = string.Empty;
            try
            {
                var suspensionId = EvalSuspensionId();
                if (string.IsNullOrWhiteSpace(suspensionId))
                {
                    throw new Exception(ErrorResource.ManualResumptionSuspensionIdBlank);
                }

                if (!_persistenceEnabled)
                {
                    throw new Exception(ErrorResource.PersistenceSettingsNoConfigured);
                }

                _logger.Info("Performing Resume of job {" + suspensionId + "}, connection established.", suspensionId);

                const string OverrideVariables = "";
                if (OverrideInputVariables)
                {
                    var persistedValues = _scheduler.GetPersistedValues(suspensionId);
                    if (string.IsNullOrEmpty(persistedValues.SuspendedEnvironment))
                    {
                        throw new Exception(ErrorResource.ManualResumptionSuspensionEnvBlank);
                    }

                    if (persistedValues.SuspendedEnvironment.StartsWith("Failed:"))
                    {
                        throw new Exception(persistedValues.SuspendedEnvironment);
                    }
                    var envArray     = _dataObject.Environment.ToJson();
                    var resumeObject = _dataObject;
                    resumeObject.StartActivityId = persistedValues.StartActivityId;
                    resumeObject.Environment.FromJson(persistedValues.SuspendedEnvironment);
                    resumeObject.Environment.FromJson(envArray);
                    resumeObject.ExecutingUser = persistedValues.ExecutingUser;
                    InnerActivity(resumeObject, _update);
                    Response = _scheduler.ManualResumeWithOverrideJob(resumeObject, suspensionId);
                }
                else
                {
                    Response = _scheduler.ResumeJob(_dataObject, suspensionId, OverrideInputVariables, OverrideVariables);
                }

                _stateNotifier?.LogActivityExecuteState(this);
                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams("SuspensionID: " + suspensionId, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    debugItemStaticDataParams = new DebugItemStaticDataParams("Override Variables: " + OverrideInputVariables, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    debugItemStaticDataParams = new DebugItemStaticDataParams("Result: " + Response, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                LogException(new Exception(ErrorResource.BackgroundJobClientResumeFailed), allErrors);
            }
            catch (Exception ex)
            {
                LogException(ex, allErrors);
            }
            finally
            {
                HandleErrors(_dataObject, allErrors);
            }

            return(new List <string> {
                Response
            });
        }
 public void OnCreating(CreatingContext context)
 {
     _hangfireLogger.InfoFormat("Creating a job based on method {0}...", context.Job.Method.Name);
     _logger.Info("Creating a job based on method {" + context.Job.Method.Name + "}...");
 }