示例#1
0
        public override void Execute()
        {
            _LogManager.Info("About to execute JobSubmitter. Total jobs to submit: " + JobCacheMngr.Instance().GetJobCacheCount());
            JobRequest         job      = null;
            Guid               jobId    = Guid.Empty;
            DirectorWSAWrapper wrapper  = new DirectorWSAWrapper();
            string             response = "";
            bool               init     = wrapper.InitializeGenericConnector(ref response);

            if (!init)
            {
                wrapper.LogManager().Error("JobSubmitter failed to initialize DirectorWSAWrapper: " + response);
                return;
            }
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            string fullPath   = wrapper.DirectorSettings.CustomUncPathForInputDocs;
            int    currentJob = 0;
            string subfolder  = _ThreadTag;

            if (_MaxNumberFilesInSubfolder > 0)
            {
                subfolder = _ThreadTag + "\\" + DateTime.Now.ToString(DefaultTimeFormat);
                fullPath  = System.IO.Path.Combine(wrapper.DirectorSettings.CustomUncPathForInputDocs, subfolder);
                System.IO.Directory.CreateDirectory(fullPath);
            }
            Thread.Sleep(500); //let everybody else to start
            while (NeedStop() == false)
            {
                job   = null;
                jobId = Guid.Empty;
                if (NeedStop() == true)
                {
                    break;
                }
                if (_SleepBetweenJobs > 0)
                {
                    System.Threading.Thread.Sleep(_SleepBetweenJobs);
                }
                try
                {
                    job = JobCacheMngr.Instance().GetNextJobFromCache();
                    if (job == null)
                    {
                        _LogManager.Info("Exiting JobSubmitter, because there are no more jobs to submit.");
                        break;
                    }

                    if (_MaxNumberFilesInSubfolder > 0 && currentJob >= _MaxNumberFilesInSubfolder)
                    {
                        subfolder = _ThreadTag + "\\" + DateTime.Now.ToString(DefaultTimeFormat);
                        fullPath  = System.IO.Path.Combine(wrapper.DirectorSettings.CustomUncPathForInputDocs, subfolder);
                        System.IO.Directory.CreateDirectory(fullPath);
                        currentJob = 0;
                    }

                    watch.Reset();
                    watch.Start();
                    string tempSubfolder = subfolder;
                    if (!string.IsNullOrEmpty(job.NickName))
                    {
                        if (!string.IsNullOrEmpty(tempSubfolder))
                        {
                            tempSubfolder += "\\";
                        }
                        tempSubfolder += job.NickName;
                    }
                    if (job.SubmitAsOneCall)
                    {
                        jobId = wrapper.SubmitJobSimple(job.InputFileList, job.MetadataList, tempSubfolder, Guid.NewGuid());
                    }
                    else
                    {
                        jobId = wrapper.SubmitDocuments(job.InputFileList, job.MetadataList, false, tempSubfolder);
                    }
                    currentJob++;
                    watch.Stop();
                    if (jobId == Guid.Empty)
                    {
                        _LogManager.Error("JobSubmitter failed to submit job. See log for details.");
                    }
                    else
                    {
                        job.JobId = jobId;
                        JobCacheMngr.Instance().AddToJobWatchCache(job);
                        _LogManager.Info(string.Format("JobSubmitter added new job: {0}. Duration: {1}ms", jobId, watch.ElapsedMilliseconds));
                    }
                }
                catch (Exception ee)
                {
                    _LogManager.Warn("Failed to submit job: " + ee.Message);
                }
                finally
                {
                }
            }
        }
示例#2
0
        private bool SubmitDocuments(List <string> docList, bool submitSeparately, int numOfRepeats, bool transferToRepository, bool useOneCall, ref List <JobManagerFile> JobIDS)
        {
            List <string> listToSubmit    = new List <string>();
            bool          result          = true;
            bool          singleJobResult = false;
            //List<DirectorWSAWrapper.DirectorWSA.Metadata> metadataListToSubmit = new List<Adlib.Director.DirectorWSAWrapper.DirectorWSA.Metadata>();
            List <Adlib.Director.DirectorWSAWrapper.JobManagementService.Metadata> metadataListToSubmit = new List <Adlib.Director.DirectorWSAWrapper.JobManagementService.Metadata>();

            //DirectorWSAWrapper.JobManagementService.Metadata

            if (numOfRepeats < 1)
            {
                numOfRepeats = 1;
            }
            DateTime dtAllStart = DateTime.Now;
            int      jobCount   = 0;

            for (int i = 0; i < numOfRepeats; i++)
            {
                metadataListToSubmit.Clear();
                if (_MetadataList != null && _MetadataList.Count > 0)
                {
                    //need to make a copy, because this list can be modified before submitting to DirectorWSA.
                    metadataListToSubmit = _MetadataList.GetRange(0, _MetadataList.Count);
                }

                DateTime dtStart = DateTime.Now;
                if (submitSeparately)
                {
                    foreach (string docPath in docList)
                    {
                        listToSubmit.Clear();
                        if (File.Exists(docPath))
                        {
                            listToSubmit.Add(docPath);
                            singleJobResult = false;
                            Guid jobId = Guid.Empty;

                            if (!useOneCall)
                            {
                                jobId = _DirectorWrapper.SubmitDocuments(listToSubmit, metadataListToSubmit, transferToRepository);
                            }
                            else
                            {
                                jobId = _DirectorWrapper.SubmitJobSimple(listToSubmit, metadataListToSubmit, Guid.NewGuid());
                            }
                            jobCount++;
                            if (jobId != Guid.Empty)
                            {
                                singleJobResult = true;
                            }
                            JobIDS.Add(new JobManagerFile {
                                jobID = jobId, IntpuFileName = Path.GetFileName(docPath)
                            });
                            result &= singleJobResult;
                            //System.Threading.Thread.Sleep(100);
                        }
                    }
                }
                else
                {
                    singleJobResult = false;
                    Guid jobId = Guid.Empty;

                    if (!useOneCall)
                    {
                        jobId = _DirectorWrapper.SubmitDocuments(docList, metadataListToSubmit, transferToRepository);
                    }
                    else
                    {
                        jobId = _DirectorWrapper.SubmitJobSimple(docList, metadataListToSubmit, Guid.NewGuid());
                    }
                    jobCount++;
                    if (jobId != Guid.Empty)
                    {
                        singleJobResult = true;
                    }
                    result &= singleJobResult;
                    JobIDS.Add(new JobManagerFile {
                        jobID = jobId, IntpuFileName = Path.GetFileName(docList.FirstOrDefault())
                    });
                }

                TimeSpan ts = DateTime.Now - dtStart;
                _DirectorWrapper.LogManager().Info(string.Format("Job submission took {0} sec", ts.TotalMilliseconds / 1000));
                //System.Threading.Thread.Sleep(100);
            }
            TimeSpan ts1 = DateTime.Now - dtAllStart;

            _DirectorWrapper.LogManager().Info(string.Format("All batch of Job submission took {0} sec. Job count: {1}", ts1.TotalMilliseconds / 1000, jobCount));

            return(result);
        }