public bool Add(Cooldown cooldown) { if (string.IsNullOrEmpty(cooldown?.UserId)) { throw new ArgumentException("Invalid cooldown parameters."); } if (IsCooldownInEffect(cooldown.UserId)) { return(false); } _cooldownMap.AddOrUpdate(cooldown.UserId, cooldown, (string key, Cooldown c) => { return(cooldown); }); return(true); }
private ActionInserterResponse AppendAction(Action action) { var duration = _clock.UtcNow + TimeSpan.FromMilliseconds(action.CooldownDurationMilisecs); var cooldown = new Cooldown(action.OwnerId, duration); if (_cooldownRegistry.Add(cooldown)) { _actionRepository.PushInto(action); return(new ActionInserterResponse { Success = true, NextActionAvailableUtc = duration }); } else { _logger.Error($"Failed to insert cooldown for user id '{action.OwnerId} with action '{action.Name}'"); } return(new ActionInserterResponse { Success = false }); }