예제 #1
0
        private async Task <RecoverMisfiredJobsResult> Manage()
        {
            try
            {
                log.Debug("Scanning for misfires...");

                RecoverMisfiredJobsResult res = await jobStoreSupport.DoRecoverMisfires(requestorId, cancellationTokenSource.Token).ConfigureAwait(false);

                numFails = 0;
                return(res);
            }
            catch (Exception e)
            {
                if (numFails % jobStoreSupport.RetryableActionErrorLogThreshold == 0)
                {
                    log.ErrorException("Error handling misfires: " + e.Message, e);
                }
                numFails++;
            }
            return(RecoverMisfiredJobsResult.NoOp);
        }
예제 #2
0
        private async Task Run()
        {
            var token = cancellationTokenSource.Token;

            while (!token.IsCancellationRequested)
            {
                token.ThrowIfCancellationRequested();

                DateTimeOffset sTime = SystemTime.UtcNow();

                RecoverMisfiredJobsResult recoverMisfiredJobsResult = await Manage().ConfigureAwait(false);

                if (recoverMisfiredJobsResult.ProcessedMisfiredTriggerCount > 0)
                {
                    jobStoreSupport.SignalSchedulingChangeImmediately(recoverMisfiredJobsResult.EarliestNewTime);
                }

                token.ThrowIfCancellationRequested();

                TimeSpan timeToSleep = TimeSpan.FromMilliseconds(50); // At least a short pause to help balance threads
                if (!recoverMisfiredJobsResult.HasMoreMisfiredTriggers)
                {
                    timeToSleep = jobStoreSupport.MisfireThreshold - (SystemTime.UtcNow() - sTime);
                    if (timeToSleep <= TimeSpan.Zero)
                    {
                        timeToSleep = TimeSpan.FromMilliseconds(50);
                    }

                    if (numFails > 0)
                    {
                        timeToSleep = jobStoreSupport.DbRetryInterval > timeToSleep ? jobStoreSupport.DbRetryInterval : timeToSleep;
                    }
                }

                await Task.Delay(timeToSleep, token).ConfigureAwait(false);
            }
        }