Esempio n. 1
0
        private void RefreshQuotaIfNeeded()
        {
            if (!IsRefreshNeeded())
            {
                return;
            }

            lock (locker)
            {
                if (IsRefreshNeeded())//Double check
                {
                    Log.DebugFormat("refreshing qouta. interval: {0} Last refresh was at: {1}", refreshTimeout, lastRefresh);

                    //Do quota refresh
                    lastRefresh = DateTime.UtcNow.AddMinutes(1);
                    try
                    {
                        var r = new GetSendQuotaRequest();
                        quota      = ses.GetSendQuotaAsync(r).Result;
                        sendWindow = TimeSpan.FromSeconds(1.0 / quota.MaxSendRate);
                        Log.DebugFormat("quota: {0}/{1} at {2} mps. send window:{3}", quota.SentLast24Hours, quota.Max24HourSend, quota.MaxSendRate, sendWindow);
                    }
                    catch (Exception e)
                    {
                        Log.Error("error refreshing quota", e);
                    }
                }
            }
        }
Esempio n. 2
0
        protected virtual void GetAmazonQuota()
        {
            _amazonLimitsReceived = false;

            //quota request also increments messages sent counter
            InsertTime();

            using (var client = new AmazonSimpleEmailServiceClient(_credentials.AwsAccessKey,
                                                                   _credentials.AwsSecretKey, _credentials.RegionEndpoint))
            {
                try
                {
                    GetSendQuotaResponse response = client.GetSendQuotaAsync().Result;

                    _max24HourSend.Limit  = (int)response.Max24HourSend;
                    _max24HourSend.Period = TimeSpan.FromHours(24);

                    _maxSecondSend.Limit  = (int)response.MaxSendRate;
                    _maxSecondSend.Period = TimeSpan.FromSeconds(1);

                    _amazonLimitsReceived = true;
                }
                catch (Exception sesException)
                {
                    _logger.LogError(sesException, "Exceptions while AWS SES quota request");
                }
            }
        }
Esempio n. 3
0
        public async Task InitializeAsync(
            CancellationToken ct)
        {
            amazonSES = new AmazonSimpleEmailServiceClient(
                options.AwsAccessKeyId,
                options.AwsSecretAccessKey,
                RegionEndpoint.GetBySystemName(options.Region));

            await amazonSES.GetSendQuotaAsync(ct);
        }