public RFProcessingResult Process(RFInstruction i, IRFProcessingContext processingContext) { try { if (i is RFProcessInstruction) { var pi = i as RFProcessInstruction; if (_processes.ContainsKey(pi.ProcessName)) { var process = _processes[pi.ProcessName]; return(ProcessInstruction(process, i as RFProcessInstruction, processingContext)); } else { var msg = String.Format("Process {0} referenced by instruction {1} not found in engine configuration.", pi.ProcessName, i); Log.Error(this, msg); return(RFProcessingResult.Error(new string[] { msg }, false)); } } } catch (Exception ex) { Log.Exception(this, ex, "Exception processing instruction {0}", i); return(RFProcessingResult.Error(new string[] { ex.Message }, false)); } return(new RFProcessingResult()); }
public void LogInstruction(object caller, RFInstruction i) { /*if (!(i is RFIntervalInstruction)) * { * LogInSystemLog(caller, "INSTR", i); * }*/ }
public void QueueInstruction(object issuedBy, RFInstruction i, string processingKey) { _items.Add(new RFWorkQueueItem { Item = i, ProcessingKey = processingKey }); }
private void Update(string dispatchKey, string processName, string instanceName, RFDate?valueDate, DispatchState state, long?weight, RFProcessingResult result, RFInstruction instruction) { try { using (var conn = new SqlConnection(_context.SystemConfig.DocumentStoreConnectionString)) { conn.Open(); using (var cmd = new SqlCommand("RIFF.UpdateDispatchQueue", conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Environment", RFStringHelpers.StringToSQL(_context.SystemConfig.Environment, false, 10, false)); cmd.Parameters.AddWithValue("@ItemType", (int)ItemType.GraphProcessInstruction); cmd.Parameters.AddWithValue("@DispatchKey", RFStringHelpers.StringToSQL(dispatchKey, false, 140, false)); cmd.Parameters.AddWithValue("@ProcessName", RFStringHelpers.StringToSQL(processName, true, 100, false)); cmd.Parameters.AddWithValue("@GraphInstance", RFStringHelpers.StringToSQL(instanceName, true, 20, false)); if (valueDate != null && valueDate.Value.IsValid()) { cmd.Parameters.AddWithValue("@ValueDate", valueDate.Value.Date); } else { cmd.Parameters.AddWithValue("@ValueDate", DBNull.Value); } if (weight.HasValue) { cmd.Parameters.AddWithValue("@Weight", weight.Value); } else { cmd.Parameters.AddWithValue("@Weight", DBNull.Value); } cmd.Parameters.AddWithValue("@DispatchState", (int)state); if (state == DispatchState.Started) { cmd.Parameters.AddWithValue("@LastStart", DateTimeOffset.Now); } else { cmd.Parameters.AddWithValue("@LastStart", DBNull.Value); } if (result?.Messages != null) { cmd.Parameters.AddWithValue("@Message", RFStringHelpers.StringToSQL(String.Join("|", result.Messages), true, 200, false)); } else if (state == DispatchState.Finished || state == DispatchState.Skipped || state == DispatchState.Started) { cmd.Parameters.AddWithValue("@Message", String.Empty); // clear past error messages } else { cmd.Parameters.AddWithValue("@Message", DBNull.Value); } if (result != null) { cmd.Parameters.AddWithValue("@ShouldRetry", result.ShouldRetry); } else { cmd.Parameters.AddWithValue("@ShouldRetry", false); } if (state == DispatchState.Queued && instruction != null) { cmd.Parameters.AddWithValue("@InstructionType", RFStringHelpers.StringToSQL(instruction.GetType().FullName, false, 200, false)); cmd.Parameters.AddWithValue("@InstructionContent", RFXMLSerializer.SerializeContract(instruction)); } else { cmd.Parameters.AddWithValue("@InstructionType", DBNull.Value); cmd.Parameters.AddWithValue("@InstructionContent", DBNull.Value); } cmd.ExecuteNonQuery(); } } } catch (Exception ex) { _context.Log.Exception(this, "Error updating Dispatch Store", ex); } }
public void QueueInstruction(object raisedBy, RFInstruction instruction) { _instructions.QueueInstruction(raisedBy, instruction, ProcessingKey); }
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"); }