示例#1
0
        private IScheduledTask ScheduleInternal(TimeSpan initialDelay, TimeSpan period,
                                                Func <CancellationToken, Task> action, Func <IFailureContext, CancellationToken, Task> onException,
                                                TimeSpan maxBackoffPeriod)
        {
            SchedulerAssertions.Assert(initialDelay, period, action, onException, maxBackoffPeriod);

            var t = new TestScheduledTask(Now.Add(initialDelay), period, action, onException,
                                          maxBackoffPeriod, () => Now);

            _timers.TryAdd(t, null);

            return(t);
        }
示例#2
0
        private static async Task CallAction(TestScheduledTask testScheduledTask)
        {
            try
            {
                await testScheduledTask.Action(CancellationToken.None).ConfigureAwait(false);

                testScheduledTask.FailureContext.Reset();
            }
            catch (Exception ex)
            {
                try
                {
                    testScheduledTask.FailureContext.SetException(ex);
                    await testScheduledTask.OnException(testScheduledTask.FailureContext, CancellationToken.None)
                    .ConfigureAwait(false);
                }
                catch
                {
                    // dont do anything if we failed to log
                }
            }
        }