public static void SkippingCommand(long deploymentId, ICommand command, CommandRunStats runStats, int maxRunCount, TimeSpan coolOffPeriod, TimeSpan elapsedTime) { string msg = $"Skipping command \"{command.Show()}\" in deployment {deploymentId}."; runStats.Exception.ForEach(ex => msg += $" Error: {ex.Message}."); if (runStats.RunCount == maxRunCount) { if (runStats.LoggedWarning == false) { msg += $" Command has been tried {runStats.RunCount} times. Giving up (max run count is {maxRunCount})."; Log.LogWarning((int)EventIds.SkippingCommand, msg); runStats.LoggedWarning = true; } } else { msg += $" Will retry in {(coolOffPeriod - elapsedTime).Humanize()}"; Log.LogDebug((int)EventIds.SkippingCommand, msg); } }
) ShouldRunCommand(ICommand command) { // the command should be run if there's no entry for it in our status dictionary if (this.commandRunStatus.ContainsKey(command.Id) == false) { return(true, -1, TimeSpan.MinValue, TimeSpan.MinValue); } CommandRunStats commandRunStatus = this.commandRunStatus[command.Id]; // if this command has been run maxRunCount times already then don't // run it anymore if (commandRunStatus.RunCount == this.maxRunCount) { return(false, commandRunStatus.RunCount, TimeSpan.MinValue, TimeSpan.MinValue); } TimeSpan coolOffPeriod = TimeSpan.FromSeconds( this.coolOffTimeUnitInSeconds * Math.Pow(2, commandRunStatus.RunCount) ); TimeSpan elapsedTime = this.systemTime.UtcNow - commandRunStatus.LastRunTimeUtc; return(elapsedTime > coolOffPeriod, commandRunStatus.RunCount, coolOffPeriod, elapsedTime); }