public async Task Handle(MxRecordsPolled message)
        {
            string domainName = message.Id.ToLower();

            MxEntityState state = await LoadState(domainName, nameof(message));

            MxState oldState       = state.MxState;
            int     oldRecordCount = state.HostMxRecords?.Count ?? 0;
            int     newRecordCount = message.Records?.Count ?? 0;

            _changeNotifiersComposite.Handle(state, message);

            List <HostMxRecord> validHostRecords = new List <HostMxRecord>();

            if (message.Records != null)
            {
                foreach (HostMxRecord hostRecord in message.Records)
                {
                    if (Uri.CheckHostName(hostRecord.Id) != UriHostNameType.Unknown)
                    {
                        validHostRecords.Add(hostRecord);
                    }
                    else
                    {
                        _log.LogInformation($"Erroneous host: {hostRecord.Id} found for domain: {domainName}");
                    }
                }
            }

            if (message.Error == null)
            {
                state.HostMxRecords = validHostRecords;
            }

            state.LastUpdated = message.Timestamp;
            state.Error       = message.Error;
            state.MxState     = MxState.Evaluated;

            await _dao.Save(state);

            _log.LogInformation($"Updated MxEntity from {oldState} to {MxState.Evaluated} and MX records before: {oldRecordCount} after: {newRecordCount} for {domainName}.");

            Message mxRecordsUpdated = new MxRecordsUpdated(domainName, validHostRecords);

            _dispatcher.Dispatch(mxRecordsUpdated, _mxEntityConfig.SnsTopicArn);
            _log.LogInformation($"An MxRecordsUpdated message for Domain: {domainName} has been dispatched to SnsTopic: {_mxEntityConfig.SnsTopicArn}");

            // Should probably change this so it only happens for a new host
            validHostRecords?.ForEach(mxRecord => {
                _dispatcher.Dispatch(new MxHostTestPending(mxRecord.Id), _mxEntityConfig.SnsTopicArn);
                _log.LogInformation($"An MxHostTestPending message for Host: {mxRecord.Id} has been dispatched to SnsTopic: {_mxEntityConfig.SnsTopicArn}");
            });

            Message createScheduledReminder = new CreateScheduledReminder(Guid.NewGuid().ToString(), "Mx", domainName, _clock.GetDateTimeUtc().AddSeconds(_mxEntityConfig.NextScheduledInSeconds));

            _dispatcher.Dispatch(createScheduledReminder, _mxEntityConfig.SnsTopicArn);
            _log.LogInformation($"A CreateScheduledReminder message for Domain: {domainName} has been dispatched to SnsTopic: {_mxEntityConfig.SnsTopicArn}");
        }
Пример #2
0
        public async Task UpdateState(string domain, MxState state)
        {
            var parameters = new Dictionary <string, object>
            {
                ["domain"]      = ReverseUrl(domain),
                ["mxState"]     = state,
                ["error"]       = null,
                ["lastUpdated"] = null
            };

            await _saveOperation(MxStateDaoResources.UpsertDomain, parameters);
        }