예제 #1
0
        /// <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 at very beginning of Job
            StaticClass.NumberOfJobsExecuting++;

            // Create the Job Run common strings
            string job = jobXmlData.Job;
            string processingBufferDirectory = StaticClass.IniData.ProcessingDir;
            string processingBufferJobDir    = processingBufferDirectory + @"\" + job;

            // Get the Job xml data
            StatusMonitorData monitorData = StaticClass.GetJobMonitorData(jobXmlData);

            // Add initial entry to status list
            StaticClass.StatusDataEntry(job, JobStatus.JOB_STARTED, JobType.TIME_RECEIVED);

            // Set the job start time
            StaticClass.JobStartTime[job] = DateTime.Now;

            // 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("RunJob before start") == true)
            {
                return;
            }

            // Add entry to status list
            StaticClass.StatusDataEntry(job, JobStatus.EXECUTING, JobType.TIME_START);

            StaticClass.Log(string.Format("Starting Processing 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("RunJob Processing 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 handling
            RunJobCompleteProcessing(job, monitorData);

            // Add job complete 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 at very end of Job
            StaticClass.NumberOfJobsExecuting--;
        }