示例#1
0
            public async Task OnTimerTick(AverageTimeSpanStatistic tardinessStat, Logger Logger)
            {
                var before = DateTime.UtcNow;
                var status = TickStatus.NewStruct(firstTickTime, period, before);

                if (Logger.IsVerbose2)
                {
                    Logger.Verbose2("Triggering tick for {0}, status {1}, now {2}", this.ToString(), status, before);
                }

                try
                {
                    if (null != stopwatch)
                    {
                        stopwatch.Stop();
                        var tardiness = stopwatch.Elapsed - period;
                        tardinessStat.AddSample(Math.Max(0, tardiness.Ticks));
                    }
                    await remindable.ReceiveReminder(ReminderName, status);

                    if (null == stopwatch)
                    {
                        stopwatch = new Stopwatch();
                    }

                    stopwatch.Restart();

                    var after = DateTime.UtcNow;
                    if (Logger.IsVerbose2)
                    {
                        Logger.Verbose2("Tick triggered for {0}, dt {1} sec, next@~ {2}", this.ToString(), (after - before).TotalSeconds,
                                        // the next tick isn't actually scheduled until we return control to
                                        // AsyncSafeTimer but we can approximate it by adding the period of the reminder
                                        // to the after time.
                                        after + period);
                    }
                }
                catch (Exception exc)
                {
                    var after = DateTime.UtcNow;
                    Logger.Error(
                        ErrorCode.RS_Tick_Delivery_Error,
                        String.Format("Could not deliver reminder tick for {0}, next {1}.", this.ToString(), after + period),
                        exc);
                    // What to do with repeated failures to deliver a reminder's ticks?
                }
            }
示例#2
0
            public async Task OnTimerTick()
            {
                var before = DateTime.UtcNow;
                var status = TickStatus.NewStruct(firstTickTime, period, before);

                var logger = this.reminderService.logger;

                if (logger.IsEnabled(LogLevel.Trace))
                {
                    logger.Trace("Triggering tick for {0}, status {1}, now {2}", this.ToString(), status, before);
                }

                try
                {
                    if (stopwatch.IsRunning)
                    {
                        stopwatch.Stop();
                        var tardiness = stopwatch.Elapsed - period;
                        this.reminderService.tardinessStat.AddSample(Math.Max(0, tardiness.Ticks));
                    }

                    await remindable.ReceiveReminder(Identity.ReminderName, status);

                    stopwatch.Restart();

                    var after = DateTime.UtcNow;
                    if (logger.IsEnabled(LogLevel.Trace))
                    {
                        logger.Trace("Tick triggered for {0}, dt {1} sec, next@~ {2}", this.ToString(), (after - before).TotalSeconds,
                                     // the next tick isn't actually scheduled until we return control to
                                     // AsyncSafeTimer but we can approximate it by adding the period of the reminder
                                     // to the after time.
                                     after + this.period);
                    }
                }
                catch (Exception exc)
                {
                    var after = DateTime.UtcNow;
                    logger.Error(
                        ErrorCode.RS_Tick_Delivery_Error,
                        string.Format("Could not deliver reminder tick for {0}, next {1}.", this.ToString(), after + this.period),
                        exc);
                    // What to do with repeated failures to deliver a reminder's ticks?
                }
            }