Skip to content

Commit

Permalink
Added exception handling to show status bar error when resolving events
Browse files Browse the repository at this point in the history
  • Loading branch information
jschick04 authored and bill-long committed Mar 15, 2024
1 parent 2bea3e5 commit c915d30
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 48 deletions.
102 changes: 55 additions & 47 deletions src/EventLogExpert.UI/Store/EventLog/EventLogEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,45 +120,45 @@ public async Task HandleOpenLog(EventLogAction.OpenLog action, IDispatcher dispa

dispatcher.Dispatch(new EventTableAction.AddTable(logData));

try
{
EventRecord? lastEvent = null;
EventRecord? lastEvent = null;

const int batchSize = 200;
bool doneReading = false;
ConcurrentQueue<EventRecord> records = new();
ConcurrentQueue<DisplayEventModel> events = new();
const int batchSize = 200;
bool doneReading = false;
ConcurrentQueue<EventRecord> records = new();
ConcurrentQueue<DisplayEventModel> events = new();

await using Timer timer = new(
s => { dispatcher.Dispatch(new StatusBarAction.SetEventsLoading(activityId, events.Count)); },
null,
TimeSpan.Zero,
TimeSpan.FromSeconds(1));
await using Timer timer = new(
_ => { dispatcher.Dispatch(new StatusBarAction.SetEventsLoading(activityId, events.Count)); },
null,
TimeSpan.Zero,
TimeSpan.FromSeconds(1));

try
{
// Don't need to wait on this since we are waiting for doneReading in the resolver tasks
_ = Task.Run(() =>
{
using var reader = new EventLogReader(eventLog);
{
using var reader = new EventLogReader(eventLog);

int count = 0;
int count = 0;

while (reader.ReadEvent() is { } e)
{
action.Token.ThrowIfCancellationRequested();
while (reader.ReadEvent() is { } e)
{
action.Token.ThrowIfCancellationRequested();

if (count % batchSize == 0)
{
records.Enqueue(e);
}
if (count % batchSize == 0)
{
records.Enqueue(e);
}

count++;
count++;

lastEvent = e;
}
lastEvent = e;
}

doneReading = true;
},
action.Token);
doneReading = true;
},
action.Token);

await Parallel.ForEachAsync(
Enumerable.Range(1, 8),
Expand All @@ -181,38 +181,46 @@ await Parallel.ForEachAsync(

if (@event is null) { break; }

events.Enqueue(eventResolver.Resolve(@event, action.LogName));
try
{
events.Enqueue(eventResolver.Resolve(@event, action.LogName));
}
catch (Exception ex)
{
dispatcher.Dispatch(
new StatusBarAction.SetResolverStatus($"Failed to resolve RecordId: {@event.RecordId}, {ex.Message}"));
}
}
}

return ValueTask.CompletedTask;
});

dispatcher.Dispatch(new EventLogAction.LoadEvents(
logData,
events.ToList().AsReadOnly(),
events.Select(e => e.Id).ToImmutableHashSet(),
events.Select(e => e.ActivityId).ToImmutableHashSet(),
events.Select(e => e.Source).ToImmutableHashSet(),
events.Select(e => e.TaskCategory).ToImmutableHashSet(),
events.SelectMany(e => e.KeywordsDisplayNames).ToImmutableHashSet()));

dispatcher.Dispatch(new StatusBarAction.SetEventsLoading(activityId, 0));

if (action.LogType == LogType.Live)
{
logWatcherService.AddLog(action.LogName, lastEvent?.Bookmark);
}
}
catch (TaskCanceledException)
{
dispatcher.Dispatch(new EventLogAction.CloseLog(logData.Id, logData.Name));
dispatcher.Dispatch(new StatusBarAction.ClearStatus(activityId));

return;
}
finally

dispatcher.Dispatch(new EventLogAction.LoadEvents(
logData,
events.ToList().AsReadOnly(),
events.Select(e => e.Id).ToImmutableHashSet(),
events.Select(e => e.ActivityId).ToImmutableHashSet(),
events.Select(e => e.Source).ToImmutableHashSet(),
events.Select(e => e.TaskCategory).ToImmutableHashSet(),
events.SelectMany(e => e.KeywordsDisplayNames).ToImmutableHashSet()));

dispatcher.Dispatch(new StatusBarAction.SetEventsLoading(activityId, 0));

if (action.LogType == LogType.Live)
{
dispatcher.Dispatch(new StatusBarAction.SetResolverStatus(string.Empty));
logWatcherService.AddLog(action.LogName, lastEvent?.Bookmark);
}

dispatcher.Dispatch(new StatusBarAction.SetResolverStatus(string.Empty));
}

[EffectMethod]
Expand Down
2 changes: 1 addition & 1 deletion src/EventLogExpert.UI/Store/StatusBar/StatusBarReducers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace EventLogExpert.UI.Store.StatusBar;
public sealed class StatusBarReducers
{
[ReducerMethod]
public static StatusBarState ReduceCloseAll(StatusBarState state, StatusBarAction.ClearStatus action)
public static StatusBarState ReduceClearStatus(StatusBarState state, StatusBarAction.ClearStatus action)
{
var updatedState = state with { };

Expand Down

0 comments on commit c915d30

Please sign in to comment.