コード例 #1
0
        private static void StartJob(object Data)
        {
            object[] DataArray = (object[])Data;

            string   DaemonCode    = (string)DataArray[0];
            int      JobInstanceId = (int)DataArray[1];
            int      JobId         = (int)DataArray[2];
            int      JobTypeId     = (int)DataArray[3];
            int      JobPriority   = (int)DataArray[4];
            DateTime RunTime       = (DateTime)DataArray[5];
            string   JobParams     = (string)DataArray[6];

            JobParams JP = new JobParams();

            JP.Init(JobParams);

            Utils.Trace(DaemonCode + ": " + "Processing job " + JobInstanceId.ToString());

            try
            {
                Job J = JobMgr.GetJobByType(JobTypeId);

                J.Init(JobId, JobInstanceId, JobPriority, RunTime);

                string    ErrorMsg;
                JobStatus JS = J.Start(JP, out ErrorMsg);

                Utils.Trace(DaemonCode + ": " + "Updating job status " + JobInstanceId.ToString());

                SqlParameter[] Params = new SqlParameter[3];
                Params[0] = new SqlParameter("Id", JobInstanceId);
                Params[1] = new SqlParameter("Status", JS);
                Params[2] = new SqlParameter("ErrorMsg", ErrorMsg);

                Utils.ExecuteNonQuery("sproc_UpdateJobStatus", Params);
            }
            catch (Exception Ex)
            {
                string Msg = "Unable to process job. " + Ex.ToString();
                Utils.LogError(Msg);

                SqlParameter[] Params = new SqlParameter[3];
                Params[0] = new SqlParameter("Id", JobInstanceId);
                Params[1] = new SqlParameter("Status", JobStatus.Failed);
                Params[2] = new SqlParameter("ErrorMsg", Msg);

                Utils.ExecuteNonQuery("sproc_UpdateJobStatus", Params);
            }
        }
コード例 #2
0
        public void Start()
        {
            while (1 == 1)
            {
                try
                {
                    Trace("Polling DB for job parts...");

                    SqlParameter[] Params = new SqlParameter[1];
                    Params[0] = new SqlParameter("@DaemonCode", _DaemonCode);

                    DataSet DS = Utils.ExecuteDataSet("sproc_GetJobPartList", Params);

                    bool HasItemsToProcess = false;

                    foreach (DataRow DR in DS.Tables[0].Rows)
                    {
                        HasItemsToProcess = true;

                        int      JobPartId     = int.Parse(DR["Id"].ToString());
                        int      JobInstanceId = int.Parse(DR["JobInstanceId"].ToString());
                        int      JobId         = int.Parse(DR["JobId"].ToString());
                        int      JobTypeId     = int.Parse(DR["JobTypeId"].ToString());
                        int      JobPriority   = int.Parse(DR["Priority"].ToString());
                        DateTime RunTime       = DateTime.Parse(DR["RunTime"].ToString());
                        string   JobParams     = DR["Params"].ToString();

                        JobParams JP = new JobParams();
                        JP.Init(JobParams);

                        Trace("Processing job part " + JobPartId.ToString());

                        try
                        {
                            Trace("Updating job part status " + JobPartId.ToString());

                            Job J = JobMgr.GetJobByType(JobTypeId);

                            J.Init(JobId, JobInstanceId, JobPriority, RunTime, JobPartId);

                            string        ErrorMsg;
                            JobPartStatus JPS = J.StartPart(JP, out ErrorMsg);

                            Params    = new SqlParameter[3];
                            Params[0] = new SqlParameter("Id", JobPartId);
                            Params[1] = new SqlParameter("Status", JPS);
                            Params[2] = new SqlParameter("ErrorMsg", ErrorMsg);

                            Utils.ExecuteNonQuery("sproc_UpdateJobPartStatus", Params);
                        }
                        catch (Exception Ex)
                        {
                            string Msg = "Unable to process job part. " + Ex.ToString();
                            Utils.LogError(Msg);

                            Params    = new SqlParameter[3];
                            Params[0] = new SqlParameter("Id", JobPartId);
                            Params[1] = new SqlParameter("Status", JobPartStatus.Failed);

                            Utils.ExecuteNonQuery("sproc_UpdateJobPartStatus", Params);
                        }
                    }

                    if (!HasItemsToProcess)
                    {
                        Trace("No job part items to process, waiting 5 minutes...");
                        Thread.Sleep(5 * 60 * 1000);
                    }
                }
                catch (Exception Ex)
                {
                    string Msg = "Unable to process job parts queue. " + Ex.ToString();
                    Utils.LogError(Msg);

                    if (Ex.ToString().IndexOf("Login failed") != -1)
                    {
                        break;
                    }
                }
            }
        }