Skip to content

Commit

Permalink
Update actor reminder example.
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Hoff <phillip@orst.edu>
  • Loading branch information
philliphoff committed Oct 26, 2023
1 parent 3b979e6 commit 65a42c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
5 changes: 2 additions & 3 deletions examples/Actor/ActorClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace ActorClient
using System.Threading.Tasks;
using Dapr.Actors;
using Dapr.Actors.Client;
using Dapr.Actors.Communication;
using IDemoActorInterface;

/// <summary>
Expand Down Expand Up @@ -69,7 +68,7 @@ public static async Task Main(string[] args)
}
catch (ActorMethodInvocationException ex)
{
if (ex.InnerException is NotImplementedException)
if (ex.InnerException is ActorInvokeException invokeEx && invokeEx.ActualExceptionType is "System.NotImplementedException")
{
Console.WriteLine($"Got Correct Exception from actor method invocation.");
}
Expand Down Expand Up @@ -111,7 +110,7 @@ public static async Task Main(string[] args)
await Task.Delay(5000);
Console.WriteLine("Getting details of the registered reminder");
reminder = await proxy.GetReminder();
Console.WriteLine($"Received reminder is {reminder}.");
Console.WriteLine($"Received reminder is {reminder?.ToString() ?? "None"} (expecting None).");
Console.WriteLine("Registering reminder with ttl and repetitions, i.e. reminder stops when either condition is met - The reminder will repeat 2 times.");
await proxy.RegisterReminderWithTtlAndRepetitions(TimeSpan.FromSeconds(5), 2);
Console.WriteLine("Getting details of the registered reminder");
Expand Down
15 changes: 12 additions & 3 deletions examples/Actor/DemoActor/DemoActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,18 @@ public async Task RegisterReminderWithTtlAndRepetitions(TimeSpan ttl, int repeti
await this.RegisterReminderAsync("TestReminder", null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1), repetitions, ttl);
}

public async Task<IActorReminder> GetReminder()
{
return await this.GetReminderAsync("TestReminder");
public async Task<ActorReminderData> GetReminder()
{
var reminder = await this.GetReminderAsync("TestReminder");

return reminder is not null
? new ActorReminderData
{
Name = reminder.Name,
Period = reminder.Period,
DueTime = reminder.DueTime
}
: null;
}

public Task UnregisterReminder()
Expand Down
16 changes: 15 additions & 1 deletion examples/Actor/IDemoActor/IDemoActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public interface IDemoActor : IActor
/// </summary>
/// <param name="reminderName">The name of the reminder.</param>
/// <returns>A task that returns the reminder after completion.</returns>
Task<IActorReminder> GetReminder();
Task<ActorReminderData> GetReminder();

/// <summary>
/// Unregisters the registered timer.
Expand Down Expand Up @@ -132,4 +132,18 @@ public override string ToString()
return $"PropertyA: {propAValue}, PropertyB: {propBValue}";
}
}

public class ActorReminderData
{
public string Name { get; set; }

public TimeSpan DueTime { get; set; }

public TimeSpan Period { get; set; }

public override string ToString()
{
return $"Name: {this.Name}, DueTime: {this.DueTime}, Period: {this.Period}";
}
}
}

0 comments on commit 65a42c3

Please sign in to comment.