Example #1
0
        /// <summary>
        ///   Execute the plugin via the Quartz job execution handler.
        /// </summary>
        /// <param name="context">A Quartz context containing handles to various information.</param>
        /// <returns>A task that represents the asynchronous operation.</returns>
        public Task Execute(IJobExecutionContext context)
        {
            var now = DateTime.Now;

            if (QuietPeriods.IsQuietPeriod(new DateTimeOffset(now)))
            {
                _log.Info($"{Plugin.Name} was not executed because {now} is within a quiet period.");
                return(Task.FromResult <object>(null));
            }

            try
            {
                var sw = new Stopwatch();
                sw.Start();

                var status = Plugin.Execute();

                sw.Stop();

                status.Plugin = Plugin;

                _log.Debug(
                    "Executed plugin '{0}' - {1} [{2}ms]", Plugin.Name, status.Status, sw.ElapsedMilliseconds);

                NotifyListeners(status);
            }
            catch (Exception ex)
            {
                _log.Error("Exception Executing {0}: {1}", Plugin.Name, ex.ToString(), ex);
                Plugin.PluginStatus = PluginStatus.TaskExecutionFailure;
            }

            return(Task.FromResult <object>(null));
        }
Example #2
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="HealthCheckJob" /> class.
 /// </summary>
 public HealthCheckJob()
 {
     Listeners    = new List <IStatusListener>();
     QuietPeriods = new QuietPeriods();
     Triggers     = new List <ITrigger>();
     Id           = Guid.NewGuid().ToString();
 }
        private QuietPeriods GetQuietPeriods(XElement node)
        {
            var periods = new QuietPeriods();

            var exclusionsNode = node.Element("QuietPeriods");

            foreach (var exclusion in exclusionsNode.Elements().ToList())
            {
                var exclusionType = ReadAttribute(exclusion, "Type");

                switch (exclusionType)
                {
                case "cron":
                    periods.AddCalendar(new CronCalendar(ReadAttribute(exclusion, "Expression")));
                    break;

                default:
                    _log.Warn("Unrecognized quiet period type: {0}", exclusionType);
                    break;
                }
            }

            return(periods);
        }