Example #1
0
        public void SaveTriggerStatistic(TriggerStatistic triggerStat)
        {
            //Cache cacheItem = new System.Web.Caching.Cache();
            List <TriggerStatistic> triggerStats = (List <TriggerStatistic>)cache[Common.Constants.PerformanceDataCacheKey];

            //If JobStat collection is null or empty, initialize it first before adding a new entry
            if (triggerStats == null)
            {
                triggerStats = new List <TriggerStatistic>();
            }

            triggerStats.Add(triggerStat);
            cache[Common.Constants.PerformanceDataCacheKey] = triggerStats;
        }
        public void TriggerComplete(ITrigger trigger, IJobExecutionContext context, SchedulerInstruction triggerInstructionCode)
        {
            try
            {
                //var executationDuration = (DateTime.UtcNow - trigger.GetPreviousFireTimeUtc()).Value.TotalSeconds;
                var executionDuration        = context.JobRunTime.TotalSeconds;
                TriggerStatistic triggerStat = new TriggerStatistic()
                {
                    Group      = trigger.Key.Group,
                    JobKey     = trigger.JobKey.Name,
                    TriggerKey = trigger.Key.Name,
                    ExecutionDurationInSeconds = executionDuration,
                    StartTime  = trigger.GetPreviousFireTimeUtc().Value.DateTime.ToLocalTime(),
                    FinishTime = DateTime.Now
                };


                Sitecore.Diagnostics.Log.Info(String.Format("Job {0} with trigger {1} Completed @ {2} and it took {3} seconds ", triggerStat.JobKey, triggerStat.TriggerKey, DateTime.Now, triggerStat.ExecutionDurationInSeconds), this);

                string triggerStatProviderType = Settings.GetSetting("Sitecore.QuartzScheduler.TriggerStatisticsStoreProvider");

                if (!String.IsNullOrEmpty(triggerStatProviderType))
                {
                    var triggerStatsProvider = Activator.CreateInstance(Type.GetType(triggerStatProviderType)) as ITriggerStatisticsStore;
                    triggerStatsProvider.SaveTriggerStatistic(triggerStat);
                }
                else
                {
                    Sitecore.Diagnostics.Log.Warn("Sitecore.QuartzScheuler: Missing App Setting value for Sitecore.QuartzScheduler.TriggerStatisticsStoreProvider", this);
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("Exception in TriggerComplete: " + ex.Message + Environment.NewLine + ex.StackTrace, this);
            }
        }