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

Add Actor Reminder/Timer TTL support #912

Merged
merged 2 commits into from
Aug 3, 2022
Merged

Conversation

halspang
Copy link
Contributor

Description

This commit adds the TTL field to Actor reminders/timers. This allows
reminders and timers to expire after a given TimeSpan instead of
having to be manually deleted.

#788

Signed-off-by: Hal Spang halspang@microsoft.com

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #788

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

@halspang halspang requested review from a team as code owners July 22, 2022 20:20
@halspang halspang force-pushed the reminder_ttl branch 2 times, most recently from 92ae1a8 to d800f37 Compare July 22, 2022 20:26
@codecov
Copy link

codecov bot commented Jul 22, 2022

Codecov Report

Merging #912 (d235eb7) into master (e58b1de) will decrease coverage by 0.31%.
The diff coverage is 40.36%.

@@            Coverage Diff             @@
##           master     #912      +/-   ##
==========================================
- Coverage   70.11%   69.79%   -0.32%     
==========================================
  Files         152      154       +2     
  Lines        4939     5079     +140     
  Branches      543      549       +6     
==========================================
+ Hits         3463     3545      +82     
- Misses       1349     1402      +53     
- Partials      127      132       +5     
Flag Coverage Δ
net5 69.69% <40.36%> (-0.36%) ⬇️
net6 69.69% <40.36%> (-0.32%) ⬇️
netcoreapp3.1 69.75% <40.36%> (-0.32%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rc/Dapr.Actors/Runtime/DefaultActorTimerManager.cs 12.00% <0.00%> (ø)
src/Dapr.Actors/Runtime/ActorReminder.cs 19.60% <13.51%> (-23.25%) ⬇️
src/Dapr.Actors/Runtime/ActorTimer.cs 18.64% <14.63%> (-18.40%) ⬇️
src/Dapr.Actors/Runtime/Actor.cs 72.80% <50.98%> (-15.43%) ⬇️
src/Dapr.Actors/Runtime/TimerInfo.cs 72.00% <54.54%> (-3.76%) ⬇️
src/Dapr.Actors/Runtime/ActorReminderOptions.cs 100.00% <100.00%> (ø)
src/Dapr.Actors/Runtime/ActorTimerOptions.cs 100.00% <100.00%> (ø)
src/Dapr.Actors/Runtime/ReminderInfo.cs 97.43% <100.00%> (+97.43%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us.

@halspang halspang force-pushed the reminder_ttl branch 2 times, most recently from 0c6a8ca to 5e4198e Compare July 25, 2022 13:41
This commit adds the TTL field to Actor reminders/timers. This allows
reminders and timers to expire after a given TimeSpan instead of
having to be manually deleted.

dapr#788

Signed-off-by: Hal Spang <halspang@microsoft.com>
await proxy.RegisterTimer();
await proxy.RegisterReminder();
await proxy.RegisterTimer(null);
await proxy.RegisterReminder(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if this is a default-valued parameter you don't have to pass null here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ActorProxy complained about the interface having a default value and without that, the top level doesn't appear to accept the default parameter. I'll look again as maybe I was just being wrong, but that's the behavior I observed.

@@ -213,9 +214,10 @@ protected virtual Task OnPostActorMethodAsync(ActorMethodContext actorMethodCont
string reminderName,
byte[] state,
TimeSpan dueTime,
TimeSpan period)
TimeSpan period,
TimeSpan? ttl = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@rynowak rynowak Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you add the new overload, we probably can't make ttl optional, because that will cause an ambiguity in overload resolution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dang, I thought the default saved me from the breaking change. Thanks for letting me know! I'll fix this and apply throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you add the new overload, we probably can't make ttl optional, because that will cause an ambiguity in overload resolution.

So this was a problem because null is semantically important here unfortunately. I didn't want to put in something like looking for a specific TimeSpan value made us remove the TTL because who knows what people want to put in (and if it's wrong I'd rather error). So I introduced a class that allows us to pass in a null while keeping a consistent API surface. Let me know what you think, it's generally internal because it felt weird to expose it.

/// <returns>Returns IActorTimer object.</returns>
public async Task<ActorTimer> RegisterTimerAsync(
string timerName,
string callback,
byte[] callbackParams,
TimeSpan dueTime,
TimeSpan period)
TimeSpan period,
TimeSpan? ttl = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same deal, this is a breaking change.

public ActorReminder(
string actorType,
ActorId actorId,
string name,
byte[] state,
TimeSpan dueTime,
TimeSpan period)
TimeSpan period,
TimeSpan? ttl = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accidentally linked to someone's fork, but those should all be valid.

public ActorTimer(
string actorType,
ActorId actorId,
string name,
string timerCallback,
byte[] data,
TimeSpan dueTime,
TimeSpan period)
TimeSpan period,
TimeSpan? ttl = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a breaking change :)

{
this.Data = data;
this.DueTime = dueTime;
this.Period = period;
this.Ttl = ttl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a breaking change 😁 - internal type

@@ -34,14 +34,16 @@ public class TimerInfo
string callback,
byte[] state,
TimeSpan dueTime,
TimeSpan period)
TimeSpan period,
TimeSpan? ttl = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a breaking change 👍 - internal type

Signed-off-by: Hal Spang <halspang@microsoft.com>
@halspang halspang merged commit 8bc7e90 into dapr:master Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add support for TTL and time/interval formats in actor timers/reminders
2 participants