Пример #1
0
        }         // Shutdown

        private void Reinit()
        {
            try {
                ThreadContext.Properties["UserId"]       = string.Empty;
                ThreadContext.Properties["CustomerId"]   = string.Empty;
                ThreadContext.Properties["StrategyType"] = "Crontab";

                m_oLog.Debug("Updating crontab job list...");

                var oAllJobs = new JobSet();

                var oSp = new LoadEzServiceCrontab(m_oDB, m_oLog)
                {
                    IncludeRunning = true,
                };

                oSp.ForEachRowSafe(sr => {
                    try {
                        long nJobID = sr["JobID"];

                        if (oAllJobs.Contains(nJobID))
                        {
                            oAllJobs[nJobID].AddArgument(sr, m_oTypeRepo);
                        }
                        else
                        {
                            oAllJobs[nJobID] = new Job(m_oData, sr, m_oTypeRepo);
                        }
                    }
                    catch (Exception e) {
                        m_oLog.Alert(e, "Failed to load a crontab job or its argument from DB.");
                    }               // try
                });                 // for each row

                if (oAllJobs.HasChanged(m_oJobs))
                {
                    if (oAllJobs.Count == 0)
                    {
                        m_oLog.Debug("No jobs loaded from DB.");
                    }
                    else
                    {
                        m_oLog.Debug("{0} loaded from DB:", Grammar.Number(oAllJobs.Count, "crontab job"));

                        oAllJobs.Iterate((nJobID, oJob) => m_oLog.Debug("Job: {0}", oJob));

                        m_oLog.Debug("End of crontab job list.");
                    }             // if
                }                 // if

                m_oJobs = oAllJobs;

                m_oLog.Debug("Updating crontab job list complete.");
            }
            catch (Exception e) {
                m_oLog.Alert(e, "Exception caught during crontab daemon reinitialisation.");
            }     // try
        }         // Reinit
Пример #2
0
        }         // Iterate

        public bool HasChanged(JobSet oPrevious)
        {
            if (oPrevious == null)
            {
                return(true);
            }

            if (this.Count != oPrevious.Count)
            {
                return(true);
            }

            var oIDs = new SortedSet <long>();

            this.Iterate((nJobID, oJob) => oIDs.Add(nJobID));
            oPrevious.Iterate((nJobID, oJob) => oIDs.Add(nJobID));

            foreach (long nJobID in oIDs)
            {
                if (!this.Contains(nJobID))
                {
                    return(true);
                }

                if (!oPrevious.Contains(nJobID))
                {
                    return(true);
                }

                if (this[nJobID].Differs(oPrevious[nJobID]))
                {
                    return(true);
                }
            }             // for each job id

            return(false);
        }         // HasChanged