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

Update actor reminder example. #1179

Merged
merged 2 commits into from
Nov 13, 2023
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
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}";
}
}
}
Loading