private async Task <SpfEntityState> LoadState(string id, string messageType) { SpfEntityState state = await _dao.Get(id); if (state == null) { _log.LogError("Ignoring {EventName} as SPF Entity does not exist for {Id}.", messageType, id); throw new InvalidOperationException( $"Cannot handle event {messageType} as SPF Entity doesnt exists for {id}."); } return(state); }
public async Task Handle(SpfRecordExpired message) { string id = message.Id.ToLower(); SpfEntityState state = await LoadState(id, nameof(message)); Message evnt = state.UpdatePollPending(); state.Version++; await _dao.Save(state); _dispatcher.Dispatch(evnt, _spfEntityConfig.SnsTopicArn); }
public async Task Handle(SpfRecordsEvaluated message) { string id = message.Id.ToLower(); SpfEntityState state = await LoadState(id, nameof(message)); _changeNotifierComposite.Handle(state, message); _domainStatusPublisher.Publish(message); Message evnt = state.UpdateSpfEvaluation(message.Records, message.DnsQueryCount, message.ElapsedQueryTime, message.Messages, message.LastUpdated); state.Version++; await _dao.Save(state); _dispatcher.Dispatch(evnt, _spfEntityConfig.SnsTopicArn); }
public async Task Handle(DomainCreated message) { string id = message.Id.ToLower(); SpfEntityState state = await _dao.Get(id); if (state != null) { _log.LogError("Ignoring {EventName} as SpfEntity already exists for {Id}.", nameof(DomainCreated), id); throw new InvalidOperationException($"Cannot handle event {nameof(DomainCreated)} as SpfEntity already exists for {id}."); } state = new SpfEntityState(id, 1, SpfState.Created, DateTime.UtcNow); await _dao.Save(state); SpfEntityCreated spfEntityCreated = new SpfEntityCreated(id, state.Version); _dispatcher.Dispatch(spfEntityCreated, _spfEntityConfig.SnsTopicArn); _log.LogInformation("Created SpfEntity for {Id}.", id); }