mirror of https://github.com/dapr/dotnet-sdk.git
Update actor reminder example. (#1179)
Signed-off-by: Phillip Hoff <phillip@orst.edu> Co-authored-by: halspang <70976921+halspang@users.noreply.github.com>
This commit is contained in:
parent
02ab25e937
commit
2332388155
|
|
@ -18,7 +18,6 @@ namespace ActorClient
|
|||
using System.Threading.Tasks;
|
||||
using Dapr.Actors;
|
||||
using Dapr.Actors.Client;
|
||||
using Dapr.Actors.Communication;
|
||||
using IDemoActorInterface;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -69,7 +68,7 @@ namespace ActorClient
|
|||
}
|
||||
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.");
|
||||
}
|
||||
|
|
@ -111,7 +110,7 @@ namespace ActorClient
|
|||
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");
|
||||
|
|
|
|||
|
|
@ -85,9 +85,18 @@ namespace DaprDemoActor
|
|||
await this.RegisterReminderAsync("TestReminder", null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1), repetitions, ttl);
|
||||
}
|
||||
|
||||
public async Task<IActorReminder> GetReminder()
|
||||
public async Task<ActorReminderData> GetReminder()
|
||||
{
|
||||
return await this.GetReminderAsync("TestReminder");
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ namespace IDemoActorInterface
|
|||
/// </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.
|
||||
|
|
@ -132,4 +132,18 @@ namespace IDemoActorInterface
|
|||
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…
Reference in New Issue