internal async Task HandleTimerEvent()

in src/WebJobs.Extensions/Extensions/Timers/Listener/TimerListener.cs [231:284]


        internal async Task HandleTimerEvent()
        {
            bool timerStarted = false;

            try
            {
                if (_remainingInterval != TimeSpan.Zero)
                {
                    // if we're in the middle of a long interval that exceeds
                    // Timer's max interval, continue the remaining interval w/o
                    // invoking the function
                    StartTimer(_remainingInterval);
                    timerStarted = true;
                    return;
                }

                // first check to see if we're dealing with an immediate startup invocation
                if (StartupInvocation != null)
                {
                    var startupInvocation = StartupInvocation;
                    StartupInvocation = null;

                    if (startupInvocation.IsPastDue)
                    {
                        // invocation is past due
                        Logger.PastDue(_logger, _functionLogName);
                        await InvokeJobFunction(DateTime.Now, isPastDue: true, originalSchedule: startupInvocation.OriginalSchedule);
                    }
                    else if (startupInvocation.RunOnStartup)
                    {
                        // The job is configured to run immediately on startup
                        Logger.RunOnStartup(_logger, _functionLogName);
                        await InvokeJobFunction(DateTime.Now, runOnStartup: true);
                    }
                }
                else
                {
                    // this is a normal scheduled invocation
                    await InvokeJobFunction(DateTime.Now, false);
                }
            }
            catch (Exception ex)
            {
                // ensure background exceptions don't stop the execution schedule
                _logger.LogError(ex, "Error occurred during scheduled invocation for '{functionName}'.", _functionLogName);
            }
            finally
            {
                if (!timerStarted)
                {
                    StartTimer(DateTimeOffset.Now);
                }
            }
        }