Ejemplo n.º 1
0
        public void DoTheJob()
        {
            try
            {
                JobQDAL    jobqDAL    = JobQDAL.Instance;
                JobQDefDTO jobDefInfo = new JobQDefDTO();
                jobDefInfo = jobqDAL.GetJobDefDTO(jobInfo.JobDefIdent);

                if (jobDefInfo.WebServiceURL.Equals(""))
                {
                    runCommand = BuildRunCommand(jobInfo, jobDefInfo);
                    RunCmd(runCommand, jobDefInfo.MaxTimeToCompletion, ref strOut, ref strError, serviceName);
                }
                else
                {
                    url = BuildWebServiceCall(jobInfo, jobDefInfo);
                    CallWebService(url, ref strError, serviceName);
                    strOut = url;
                }
            }
            catch (Exception exc)
            {
                AddError(exc);
            }
            finally
            {
                complete = true;
            }
        }
Ejemplo n.º 2
0
        public void ProcessOutStandingJobs(string serviceName, string includedJobIdents, string excludedJobIdents)
        {
            try
            {
                Trace.WriteLine("Starting function checkForNewReport() was called");
                Trace.Indent();

                //int numberJobsProcessed = 0;
                string runCommand;
                string url;
                string jobError = "";
                string jobMessages;
                int    nMaxLength   = 7500;
                string strOut       = "";
                string strError     = "";
                string resultOutput = "";


                JobQDAL jobqDAL = JobQDAL.Instance;

                //while (ServiceRunning)
                //{
                try
                {
                    JobQDTO jobInfo = jobqDAL.GetNextJobDTO(includedJobIdents, excludedJobIdents);

                    //if (!jobInfo.JobQID.Equals(0))
                    while (jobInfo != null)
                    {
                        //numberJobsProcessed++;
                        runCommand   = "";
                        url          = "";
                        strOut       = "";
                        strError     = "";
                        resultOutput = "";
                        jobMessages  = "";
                        jobError     = "";

                        JobQDefDTO jobDefInfo = new JobQDefDTO();
                        jobDefInfo = jobqDAL.GetJobDefDTO(jobInfo.JobDefIdent);

                        strOut = " Job Id  = " + jobInfo.JobQID.ToString() + ", Service Name = " + serviceName
                                 + ", Machine Name = " + System.Environment.MachineName + ", User Name = " + System.Environment.UserDomainName + "\\" + System.Environment.UserName
                                 + ", PID = " + System.Diagnostics.Process.GetCurrentProcess().Id.ToString() + ", Assembly Version = " + Humana.H1.Common.Utilities.GetAssemblyVersionInfo() + ".     "
                                 + System.Environment.NewLine;

                        try
                        {
                            if (jobDefInfo.WebServiceURL.Equals(""))
                            {
                                string arguments = string.Empty;
                                runCommand = string.Empty;
                                BuildRunCommand(jobInfo, jobDefInfo, ref runCommand, ref arguments);
                                RunCmd(runCommand, jobDefInfo.MaxTimeToCompletion, ref strOut, ref strError, serviceName, jobInfo.JobQID, arguments);
                            }
                            else
                            {
                                url = BuildWebServiceCall(jobInfo, jobDefInfo);
                                CallWebService(url, ref strError, serviceName);
                                strOut += url;
                            }
                        }
                        catch (Exception e)
                        {
                            strError += e.ToString();
                        }

                        // sql has trouble with embedded ' char -- fix by replacing with ''
                        jobError = strError.Replace("\0", "");
                        jobError = jobError.Replace("'", "''");

                        //if (jobError.Length > nMaxLength) jobError = jobError.Substring(0, nMaxLength);
                        jobMessages = Regex.Replace(strOut, "'", "''");
                        if (jobMessages.Length > nMaxLength)
                        {
                            jobMessages = jobMessages.Substring(0, nMaxLength);
                        }

                        //Add the Job ID to the error message
                        if (jobError.Length > 0)
                        {
                            jobError = " Job Id  = " + jobInfo.JobQID.ToString() + System.Environment.NewLine
                                       + " Service Name = " + serviceName + System.Environment.NewLine
                                       + " Machine Name = " + System.Environment.MachineName + System.Environment.NewLine
                                       + " User Name = " + System.Environment.UserDomainName + "\\" + System.Environment.UserName + System.Environment.NewLine
                                       + " PID = " + System.Diagnostics.Process.GetCurrentProcess().Id.ToString() + System.Environment.NewLine
                                       + " Assembly Version = " + Humana.H1.Common.Utilities.GetAssemblyVersionInfo() + ".     "
                                       + System.Environment.NewLine
                                       + jobError;
                        }

                        jobqDAL.UpdateJobStatus(jobInfo.JobQID, jobMessages, jobError, jobDefInfo.JobOwnsStatuses);

                        //Send an email if all retrys failed
                        if (jobError.Length > 0 && jobDefInfo.JobOwnsErrorEmail == false && jobInfo.RetryCount >= jobInfo.RetryMax)
                        {
                            string subject = H1Properties.GetProperty("Adapt.Reports.CoreMetrics.Environment") + ": " + jobInfo.JobDefIdent + " Encountered An Error";
                            jobqDAL.SendEMail(jobError, subject, jobDefInfo.OnErrorEmail);
                        }

                        EventLog.WriteEntry(serviceName + ".Run", string.Format("Ran job {0} using definition for {1}.\n\nSuccess? {2}", jobInfo.JobQID, jobInfo.JobDefIdent, jobError.Length.Equals(0) ? "Yes" : "No"), EventLogEntryType.Information);

                        if (ServiceRunning)
                        {
                            jobInfo = jobqDAL.GetNextJobDTO(includedJobIdents, excludedJobIdents);
                        }
                        else
                        {
                            jobInfo = null;
                        }
                    }
                    //else
                    //{
                    //    if (numberJobsProcessed == 0)
                    //    {
                    //        resultOutput += "No Jobs found.";
                    //        Trace.WriteLine (resultOutput);
                    //    }
                    //    else
                    //    {
                    //        resultOutput += String.Format("Processed {0} Jobs.", numberJobsProcessed);
                    //    }
                    //    //break; not needed this function will be called only once
                    //}
                }
                catch (Exception e)
                {
                    EventLog.WriteEntry(serviceName + ".Run", "Error found: " + e.Message.ToString(), EventLogEntryType.Error);
                    Trace.Unindent();
                }
                //System.Threading.Thread.Sleep(SleepInterval);
                //}
            }
            catch (Exception e)
            {
                EventLog.WriteEntry(serviceName + ".Run", "Error found: " + e.Message.ToString(), EventLogEntryType.Error);
                Trace.Unindent();
            }
            Trace.Unindent();
        }