Exemple #1
0
 public FaultTolerantExecutor()
 {
     Logger = new ConsoleAndDebugLogger();
     MaxNumberOfAttempts = 1;
     ThrottlingKey       = Guid.NewGuid().ToString();
     ThrottlingDelay     = 0;
 }
Exemple #2
0
        public static void Process(
            string key,
            int timeBetweenCallsMs = 0,
            IPushLogger logger     = null)
        {
            if (logger == null)
            {
                logger = new ConsoleAndDebugLogger();
            }

            if (LastExecutionTime.ContainsKey(key))
            {
                var lastExecutionTime = LastExecutionTime[key];

                var timeSinceLastExecution = DateTime.UtcNow - lastExecutionTime;
                var throttlingDelay        = new TimeSpan(0, 0, 0, 0, timeBetweenCallsMs);

                if (timeSinceLastExecution < throttlingDelay)
                {
                    var remainingTimeToDelay = throttlingDelay - timeSinceLastExecution;

                    logger.Debug($"Intentional delay before next call: {remainingTimeToDelay} ms");

                    Thread.Sleep(remainingTimeToDelay);
                }
            }

            LastExecutionTime[key] = DateTime.UtcNow;
        }