Browse Source

Log event position

pull/728/head
Sebastian 5 years ago
parent
commit
b25f243bc4
  1. 19
      backend/src/Squidex.Infrastructure/EventSourcing/Grains/EventConsumerGrain.cs

19
backend/src/Squidex.Infrastructure/EventSourcing/Grains/EventConsumerGrain.cs

@ -101,7 +101,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
await DispatchAsync(events); await DispatchAsync(events);
State = State.Handled(position, events.Count); State = State.Handled(position, events.Count);
}); }, State.Position);
} }
public Task OnErrorAsync(object sender, Exception exception) public Task OnErrorAsync(object sender, Exception exception)
@ -116,7 +116,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
Unsubscribe(); Unsubscribe();
State = State.Stopped(exception); State = State.Stopped(exception);
}); }, State.Position);
} }
public async Task ActivateAsync() public async Task ActivateAsync()
@ -128,7 +128,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
Subscribe(); Subscribe();
State = State.Started(); State = State.Started();
}); }, State.Position);
} }
else if (!State.IsStopped) else if (!State.IsStopped)
{ {
@ -148,7 +148,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
Subscribe(); Subscribe();
State = State.Started(); State = State.Started();
}); }, State.Position);
return CreateInfo(); return CreateInfo();
} }
@ -165,7 +165,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
Unsubscribe(); Unsubscribe();
State = State.Stopped(); State = State.Stopped();
}); }, State.Position);
return CreateInfo(); return CreateInfo();
} }
@ -181,7 +181,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
State = EventConsumerState.Initial; State = EventConsumerState.Initial;
Subscribe(); Subscribe();
}); }, State.Position);
return CreateInfo(); return CreateInfo();
} }
@ -194,17 +194,17 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
} }
} }
private Task DoAndUpdateStateAsync(Action action, [CallerMemberName] string? caller = null) private Task DoAndUpdateStateAsync(Action action, string? position, [CallerMemberName] string? caller = null)
{ {
return DoAndUpdateStateAsync(() => return DoAndUpdateStateAsync(() =>
{ {
action(); action();
return Task.CompletedTask; return Task.CompletedTask;
}, caller); }, position, caller);
} }
private async Task DoAndUpdateStateAsync(Func<Task> action, [CallerMemberName] string? caller = null) private async Task DoAndUpdateStateAsync(Func<Task> action, string? position, [CallerMemberName] string? caller = null)
{ {
await semaphore.WaitAsync(); await semaphore.WaitAsync();
try try
@ -229,6 +229,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
log.LogFatal(ex, w => w log.LogFatal(ex, w => w
.WriteProperty("action", caller) .WriteProperty("action", caller)
.WriteProperty("status", "Failed") .WriteProperty("status", "Failed")
.WriteProperty("eventPosition", position)
.WriteProperty("eventConsumer", eventConsumer!.Name)); .WriteProperty("eventConsumer", eventConsumer!.Name));
State = previousState.Stopped(ex); State = previousState.Stopped(ex);

Loading…
Cancel
Save