Esempio n. 1
0
 protected void UpdateResult(RFGraphProcessorStatus status, RFProcessingResult result)
 {
     if (status != null && result != null)
     {
         if (status.CalculationOK)
         {
             var date = InstanceParams != null && GraphInstance.ValueDate.HasValue ? GraphInstance.ValueDate.Value.ToString() : "n/a";
             if (!result.WorkDone)
             {
                 Context.SystemLog.Info(this, "Run process {0} but no outputs have changed.", String.Format("{0} [{1}]", ProcessName, date));
             }
         }
         else
         {
             var date = InstanceParams != null && GraphInstance.ValueDate.HasValue ? GraphInstance.ValueDate.Value.ToString() : "n/a";
             result.AddMessage(status.Message);
             result.IsError = true;
         }
     }
 }
Esempio n. 2
0
        protected RFProcessingResult ProcessInstruction(RFEngineProcess process, RFProcessInstruction i, IRFProcessingContext processingContext)
        {
            var result = new RFProcessingResult();

            try
            {
                var  sw        = Stopwatch.StartNew();
                var  startTime = DateTimeOffset.Now;
                bool completed = false;
                try
                {
                    var processorInstance = process.CreateInstance();
                    if (processorInstance != null)
                    {
                        if (_config.MaxRuntime.Ticks > 0)
                        {
                            var maxRuntime = TimeSpan.FromTicks(Math.Max(processorInstance.MaxRuntime().Ticks, _config.MaxRuntime.Ticks));
                            var timerTask  = Task.Delay(maxRuntime).ContinueWith(t =>
                            {
                                if (!completed)
                                {
                                    try
                                    {
                                        processorInstance.Cancel();
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Warning(this, "Exception cancelling process {0}: {1}", process.Name, ex.Message);
                                    }
                                    throw new TimeoutException(String.Format("Cancelling process {0} as it's taken too long (max runtime = {1} seconds).", process.Name, maxRuntime.TotalSeconds));
                                }
                            });
                        }

                        result = process.RunInstance(processorInstance, i, processingContext);
                    }
                }
                catch (Exception ex) // hard exception, or softs should have bene handled by now
                {
                    var message = ex.InnerException?.Message ?? ex.Message;
                    result.AddMessage(message);
                    result.IsError = true;

                    result.ShouldRetry |= (ex is DbException || ex is TimeoutException || ex is RFTransientSystemException || ex?.InnerException is DbException || ex?.InnerException is TimeoutException);

                    Log.Exception(this, ex, "Exception running process {0}", process.Name);

                    /*processingContext.UserLog.LogEntry(new RFUserLogEntry
                     * {
                     *  Action = "Error",
                     *  Area = null,
                     *  Description = String.Format("Error running process {0}: {1}", process.Name, message),
                     *  IsUserAction = false,
                     *  IsWarning = true,
                     *  Processor = process.Name
                     * });*/
                }
                completed = true;
                LogProcessingStat(process, i, sw, startTime);
                Log.Debug(this, String.Format("Engine: process {0} process took {1} ms.", process.Name, sw.ElapsedMilliseconds));
            }
            catch (Exception ex) // a really bad system exception
            {
                Log.Exception(this, ex, "Exception processing instruction {0} by process {1}", i, process);

                result.AddMessage(ex.Message);
                result.IsError      = true;
                result.ShouldRetry |= (ex is DbException || ex is TimeoutException || ex is RFTransientSystemException || ex?.InnerException is DbException || ex?.InnerException is TimeoutException);
            }
            return(result);
        }
Esempio n. 3
0
        public RFProcessingResult RunInstance(IRFEngineProcessor processorInstance, RFInstruction instruction, IRFProcessingContext context)
        {
            var pi = instruction as RFProcessInstruction;

            if (pi != null)
            {
                var sw = Stopwatch.StartNew();
                RFEngineProcessorParam instanceParams = null;
                try
                {
                    instanceParams = Config.InstanceParams(instruction);
                    processorInstance.Initialize(instanceParams, context, KeyDomain, Config.Name);
                    var result = processorInstance.Process();
                    result.AddMessages(processorInstance.Log.GetErrors());
                    if ((result.WorkDone || result.IsError) && !(processorInstance is RFSchedulerProcessor))
                    {
                        context.SystemLog.LogProcess(this, processorInstance.GetProcessEntry() ?? new RFProcessEntry
                        {
                            GraphInstance  = (instanceParams as RFEngineProcessorGraphInstanceParam)?.Instance,
                            GraphName      = (processorInstance as RFGraphProcess)?.GraphName,
                            IOTime         = 0,
                            ProcessingTime = sw.ElapsedMilliseconds,
                            Message        = String.Join("\r\n", result.Messages),
                            ProcessName    = Config.Name,
                            Success        = !result.IsError,
                            NumUpdates     = 1
                        });

                        context.SystemLog.Info(this, "Run process {0}{1} in {2}ms", Config.Name, instanceParams != null ? String.Format(" ({0})", instanceParams) : String.Empty, sw.ElapsedMilliseconds);
                    }
                    return(result);
                }
                catch (RFLogicException ex) // soft exception (incorrect file etc.)
                {
                    context.UserLog.LogEntry(new RFUserLogEntry
                    {
                        Action       = "Warning",
                        IsWarning    = true,
                        Description  = String.Format("Calculation error: {0}", ex.Message),
                        IsUserAction = false,
                        Processor    = Config.Name,
                        Username     = "******",
                        Area         = null,
                        ValueDate    = RFDate.NullDate
                    });

                    context.SystemLog.Warning(this, "Logic Exception on process {0}: {1}", Config.Name, ex.Message);

                    context.SystemLog.LogProcess(this, processorInstance.GetProcessEntry() ?? new RFProcessEntry
                    {
                        GraphInstance  = (instanceParams as RFEngineProcessorGraphInstanceParam)?.Instance,
                        GraphName      = (processorInstance as RFGraphProcess)?.GraphName,
                        IOTime         = 0,
                        ProcessingTime = sw.ElapsedMilliseconds,
                        Message        = ex.Message,
                        ProcessName    = Config.Name,
                        Success        = false,
                        NumUpdates     = 0
                    });

                    var result = new RFProcessingResult
                    {
                        IsError     = true,
                        Messages    = new SortedSet <string>(processorInstance?.Log?.GetErrors() ?? new string[0]),
                        WorkDone    = false,
                        ShouldRetry = false,
                        UpdatedKeys = new System.Collections.Generic.List <RFCatalogKey>()
                    };
                    result.AddMessage(ex.Message);

                    return(result);
                }
                catch (Exception ex) // hard exception - system, null etc.
                {
                    context.SystemLog.LogProcess(this, processorInstance?.GetProcessEntry() ?? new RFProcessEntry
                    {
                        GraphInstance  = (instanceParams as RFEngineProcessorGraphInstanceParam)?.Instance,
                        GraphName      = (processorInstance as RFGraphProcess)?.GraphName,
                        IOTime         = 0,
                        ProcessingTime = sw.ElapsedMilliseconds,
                        Message        = ex.Message,
                        ProcessName    = Config.Name,
                        Success        = false,
                        NumUpdates     = 0
                    });

                    throw;
                }
            }
            throw new RFSystemException(this, "Cannot process empty instruction");
        }