/// <summary> /// Get the Job XML data /// </summary> /// <param name="directory"></param> /// <param name="scanType"></param> /// <returns>Job xml data</returns> public static JobXmlData GetJobXmlFileInfo(string directory, DirectoryScanType scanType) { JobXmlData jobScanXmlData = new JobXmlData(); string baseDirectory = (scanType == DirectoryScanType.INPUT_BUFFER) ? IniData.InputDir : IniData.ProcessingDir; string job = directory.Replace(baseDirectory, "").Remove(0, 1); jobScanXmlData.Job = job; jobScanXmlData.JobDirectory = directory; jobScanXmlData.JobSerialNumber = job.Substring(0, job.IndexOf("_")); int start = job.IndexOf("_") + 1; jobScanXmlData.TimeStamp = job.Substring(start, job.Length - start); // Wait until the Xml file shows up bool xmlFileFound = false; do { string[] files = Directory.GetFiles(directory, "*.xml"); if (files.Length > 0) { jobScanXmlData.XmlFileName = Path.GetFileName(files[0]); xmlFileFound = true; } Thread.Yield(); }while (xmlFileFound == false); return(jobScanXmlData); }
/// <summary> /// Get the Job XML data /// </summary> /// <param name="directory"></param> /// <param name="scanType"></param> /// <returns>Job Xml data</returns> public static JobXmlData GetJobXmlFileInfo(string directory, DirectoryScanType scanType) { JobXmlData jobScanXmlData = new JobXmlData(); string baseDirectory = (scanType == DirectoryScanType.INPUT_BUFFER) ? IniData.InputDir : IniData.ProcessingDir; string job = directory.Replace(baseDirectory, "").Remove(0, 1); jobScanXmlData.Job = job; jobScanXmlData.JobDirectory = directory; jobScanXmlData.JobSerialNumber = job.Substring(0, job.IndexOf("_")); int start = job.IndexOf("_") + 1; jobScanXmlData.TimeStamp = job.Substring(start, job.Length - start); Log(string.Format("Job {0} waiting for it's Job xml file at {1:HH:mm:ss.fff}", job, DateTime.Now)); // Wait until Job xml file is present to continue partial job bool xmlFileFound = false; do { string[] files = Directory.GetFiles(directory, "*.xml"); if (files.Length > 0) { jobScanXmlData.XmlFileName = Path.GetFileName(files[0]); Log(string.Format("Job {0} found it's Job xml file {1} at {2:HH:mm:ss.fff}", job, jobScanXmlData.XmlFileName, DateTime.Now)); xmlFileFound = true; } Thread.Sleep(StaticClass.JOB_XML_FILE_READY_WAIT); }while (xmlFileFound == false); return(jobScanXmlData); }
/// <summary> /// Run a job from Input or Processing Buffers /// </summary> /// <param name="dirScanType"></param> /// <param name="jobXmlData"></param> public void RunJob(JobXmlData jobXmlData, DirectoryScanType dirScanType) { // Increment number of Jobs executing in only one place! StaticClass.NumberOfJobsExecuting++; // Create the Job Run common strings string job = jobXmlData.Job; string xmlJobDirectory = jobXmlData.JobDirectory; string processingBufferDirectory = StaticClass.IniData.ProcessingDir; string processingBufferJobDir = processingBufferDirectory + @"\" + job; // Set the job start time StaticClass.JobStartTime[job] = DateTime.Now; // Create new status monitor data and fill it in with the job xml data StatusMonitorData monitorData = new StatusMonitorData { Job = job, JobDirectory = xmlJobDirectory, StartTime = DateTime.Now, JobSerialNumber = jobXmlData.JobSerialNumber, TimeStamp = jobXmlData.TimeStamp, XmlFileName = jobXmlData.XmlFileName }; // Add initial entry to status list StaticClass.StatusDataEntry(job, JobStatus.JOB_STARTED, JobType.TIME_RECEIVED); // Get the Job xml data monitorData = GetJobXmlData(jobXmlData, monitorData); // If this job comes from the Input directory, run the Input job check and start job if (dirScanType == DirectoryScanType.INPUT_BUFFER) { RunInputBufferScan(processingBufferJobDir, job, monitorData); } // If the shutdown flag is set, exit method if (StaticClass.ShutDownPauseCheck("Run Job") == true) { return; } // Add entry to status list StaticClass.StatusDataEntry(job, JobStatus.EXECUTING, JobType.TIME_START); StaticClass.Log(string.Format("Starting Job {0} with Modeler {1} on Port {2} with {3} CPU's at {4:HH:mm:ss.fff}", job, monitorData.Modeler, monitorData.JobPortNumber, StaticClass.IniData.CPUCores, DateTime.Now)); // Execute Modeler using the command line generator string executable = StaticClass.IniData.ModelerRootDir + @"\" + monitorData.Modeler + @"\" + monitorData.Modeler + ".exe"; string processingBuffer = processingBufferJobDir; int port = monitorData.JobPortNumber; int cpuCores = StaticClass.IniData.CPUCores; CommandLineGenerator cmdLineGenerator = new CommandLineGenerator( executable, processingBuffer, port, cpuCores); if (cmdLineGenerator == null) { StaticClass.Logger.LogError("JobRunThread cmdLineGenerator failed to instantiate"); } Process modelerProcess = cmdLineGenerator.ExecuteCommand(job); // Register with the Processing File Watcher class and start its thread ProcessingFileWatcherThread processingFileWatcher = new ProcessingFileWatcherThread(processingBufferJobDir, monitorData); if (processingFileWatcher == null) { StaticClass.Logger.LogError("JobRunThread ProcessingFileWatch failed to instantiate"); } processingFileWatcher.ThreadProc(); // Start the TCP/IP Communications thread before checking for Processing job files TcpIpListenThread tcpIpThread = new TcpIpListenThread(monitorData); if (tcpIpThread == null) { StaticClass.Logger.LogError("ProcessingFileWatcherThread tcpIpThread failed to instantiate"); } tcpIpThread.ThreadProc(); // Add entry to status list StaticClass.StatusDataEntry(job, JobStatus.MONITORING_PROCESSING, JobType.TIME_START); // Wait 45 seconds for Modeler to get started before reading it's information Thread.Sleep(StaticClass.DISPLAY_PROCESS_DATA_WAIT); // Display the Modeler Process information DisplayProcessInfo(job, modelerProcess); // Wait for the Processing job scan complete or shut down do { if (StaticClass.ShutDownPauseCheck("Run Job") == true) { return; } Thread.Yield(); }while ((StaticClass.ProcessingJobScanComplete[job] == false) && (StaticClass.JobShutdownFlag[job] == false)); // Wait to make sure the data.xml is done being handled Thread.Sleep(StaticClass.POST_PROCESS_WAIT); if (StaticClass.JobShutdownFlag[job] == false) { // Wait for the data.xml file to contain a result string dataXmlFileName = processingBufferJobDir + @"\" + "data.xml"; if (OverallResultEntryCheck(dataXmlFileName) == true) { StaticClass.Log(string.Format("Overall Results check confirmed for Job {0} at {1:HH:mm:ss.fff}", job, DateTime.Now)); } else { StaticClass.Log(string.Format("Overall Results check failed for Job {0} at {1:HH:mm:ss.fff}", job, DateTime.Now)); } } // Make sure Modeler Process is stopped if (StaticClass.ProcessHandles[job].HasExited == false) { StaticClass.Log(string.Format("Shutting down Modeler Executable for Job {0} at {1:HH:mm:ss.fff}", job, DateTime.Now)); StaticClass.ProcessHandles[job].Kill(); StaticClass.ProcessHandles.Remove(job); // Wait for Process to end Thread.Sleep(StaticClass.SHUTDOWN_PROCESS_WAIT); } // Run the Job Complete handler RunJobFileProcessing(job, monitorData); // Add entry to status list StaticClass.StatusDataEntry(job, JobStatus.COMPLETE, JobType.TIME_COMPLETE); // Show Job Complete message TimeSpan timeSpan = DateTime.Now - StaticClass.JobStartTime[job]; StaticClass.Log(string.Format("Job {0} Complete taking {1:hh\\:mm\\:ss}. Decrementing Job count to {2} at {3:HH:mm:ss.fff}", job, timeSpan, StaticClass.NumberOfJobsExecuting - 1, DateTime.Now)); // Decrement the number of Jobs executing in one place! StaticClass.NumberOfJobsExecuting--; }
/// <summary> /// Job Run Thread constructor obtains the state information /// </summary> /// <param name="dirScanType"></param> /// <param name="jobXmlData"></param> public JobRunThread(JobXmlData jobXmlData, DirectoryScanType dirScanType) { DirScanType = dirScanType; JobRunXmlData = jobXmlData; }