Skip to content
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
31 changes: 28 additions & 3 deletions src/Dapr.Actors/Runtime/Actor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -101,10 +101,11 @@ internal async Task OnPostActorMethodAsyncInternal(ActorMethodContext actorMetho
await this.SaveStateAsync();
}

internal Task OnInvokeFailedAsync()
internal async Task OnActorMethodFailedInternalAsync(ActorMethodContext actorMethodContext, Exception e)
{
await this.OnActorMethodFailedAsync(actorMethodContext, e);
// Exception has been thrown by user code, reset the state in state manager.
return this.ResetStateAsync();
await this.ResetStateAsync();
}

internal Task ResetStateAsync()
Expand Down Expand Up @@ -190,6 +191,30 @@ protected virtual Task OnPostActorMethodAsync(ActorMethodContext actorMethodCont
return Task.CompletedTask;
}

/// <summary>
/// Override this method for performing any action when invoking actor method has thrown an exception.
/// This method is invoked by actor runtime when invoking actor method has thrown an exception.
/// </summary>
/// <param name="actorMethodContext">
/// An <see cref="ActorMethodContext"/> describing the method that was invoked by actor runtime prior to this method.
/// </param>
/// <param name="e">Exception thrown by either actor method or by OnPreActorMethodAsync/OnPostActorMethodAsync overriden methods.</param>
/// <returns>
/// Returns a <see cref="Task">Task</see> representing post-actor-method operation.
/// </returns>
/// /// <remarks>
/// This method is invoked by actor runtime prior to:
/// <list type="bullet">
/// <item><description>Invoking an actor interface method when a client request comes.</description></item>
/// <item><description>Invoking a method when a reminder fires.</description></item>
/// <item><description>Invoking a timer callback when timer fires.</description></item>
/// </list>
/// </remarks>
protected virtual Task OnActorMethodFailedAsync(ActorMethodContext actorMethodContext, Exception e)
{
return Task.CompletedTask;
}

/// <summary>
/// Registers a reminder with the actor.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Dapr.Actors/Runtime/ActorManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -355,9 +355,9 @@ private async Task<T> DispatchInternalAsync<T>(ActorId actorId, ActorMethodConte
// PostActivate will save the state, its not invoked when actorFunc invocation throws.
await actor.OnPostActorMethodAsyncInternal(actorMethodContext);
}
catch (Exception)
catch (Exception e)
{
await actor.OnInvokeFailedAsync();
await actor.OnActorMethodFailedInternalAsync(actorMethodContext, e);
throw;
}
finally
Expand Down