Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graphQL): GraphQL subscription not notified on DialogActivityCreated #1187

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,8 @@ public sealed class DialogEntity :
public void OnCreate(AggregateNode self, DateTimeOffset utcNow)
=> _domainEvents.Add(new DialogCreatedDomainEvent(Id, ServiceResource, Party, Process, PrecedingProcess));

public void OnUpdate(AggregateNode self, DateTimeOffset utcNow)
{
var changedChildren = self.Children.Where(x =>
x.State != AggregateNodeState.Unchanged &&
x.Entity is not DialogSearchTag &&
x.Entity is not DialogActivity);

var shouldProduceEvent = self.IsDirectlyModified() || changedChildren.Any();
if (shouldProduceEvent)
{
_domainEvents.Add(new DialogUpdatedDomainEvent(Id, ServiceResource, Party, Process, PrecedingProcess));
}
}
public void OnUpdate(AggregateNode self, DateTimeOffset utcNow) =>
_domainEvents.Add(new DialogUpdatedDomainEvent(Id, ServiceResource, Party, Process, PrecedingProcess));

public void OnDelete(AggregateNode self, DateTimeOffset utcNow)
=> _domainEvents.Add(new DialogDeletedDomainEvent(Id, ServiceResource, Party, Process, PrecedingProcess));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Digdir.Domain.Dialogporten.Application.Common;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Events;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Events.Activities;
using Digdir.Domain.Dialogporten.Domain.Outboxes;
using Digdir.Domain.Dialogporten.Infrastructure.GraphQl;
using Digdir.Library.Entity.Abstractions.Features.EventPublisher;
Expand Down Expand Up @@ -65,47 +64,35 @@ x.Entity is IEventPublisher publisher
public override async ValueTask<int> SavedChangesAsync(SaveChangesCompletedEventData eventData, int result,
CancellationToken cancellationToken = default)
{
foreach (var domainEvent in _domainEvents)
try
{
try
{
// If you are adding any additional cases to this switch,
// please consider making the running of the tasks parallel
var task = domainEvent switch
var tasks = _domainEvents
.Select(x => x switch
{
DialogUpdatedDomainEvent dialogUpdatedDomainEvent => _topicEventSender.SendAsync(
$"{Constants.DialogEventsTopic}{dialogUpdatedDomainEvent.DialogId}",
new DialogEventPayload
{
Id = dialogUpdatedDomainEvent.DialogId,
Type = DialogEventType.DialogUpdated
},
cancellationToken),
DialogDeletedDomainEvent dialogDeletedDomainEvent => _topicEventSender.SendAsync(
$"{Constants.DialogEventsTopic}{dialogDeletedDomainEvent.DialogId}",
new DialogEventPayload
{
Id = dialogDeletedDomainEvent.DialogId,
Type = DialogEventType.DialogDeleted
},
cancellationToken),
DialogActivityCreatedDomainEvent dialogActivityCreatedDomainEvent => _topicEventSender.SendAsync(
$"{Constants.DialogEventsTopic}{dialogActivityCreatedDomainEvent.DialogId}",
new DialogEventPayload
{
Id = dialogActivityCreatedDomainEvent.DialogId,
Type = DialogEventType.DialogUpdated
},
cancellationToken),
_ => ValueTask.CompletedTask
};

await task;
}
catch (Exception e)
{
_logger.LogError(e, "Failed to send domain event to graphQL subscription");
}
DialogUpdatedDomainEvent dialogUpdatedDomainEvent => new DialogEventPayload
{
Id = dialogUpdatedDomainEvent.DialogId,
Type = DialogEventType.DialogUpdated
},
DialogDeletedDomainEvent dialogDeletedDomainEvent => new DialogEventPayload
{
Id = dialogDeletedDomainEvent.DialogId,
Type = DialogEventType.DialogDeleted
},
_ => (DialogEventPayload?)null
})
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
.Where(x => x is not null)
.Cast<DialogEventPayload>()
.Select(x => _topicEventSender.SendAsync(
$"{Constants.DialogEventsTopic}{x.Id}",
x,
cancellationToken)
.AsTask());
await Task.WhenAll(tasks);
}
catch (Exception e)
{
_logger.LogError(e, "Failed to send domain events to graphQL subscription");
}

return await base.SavedChangesAsync(eventData, result, cancellationToken);
Expand Down
Loading