Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
Signed-off-by: joshvanl <me@joshvanl.dev>
  • Loading branch information
JoshVanL committed Oct 27, 2023
1 parent ea9999b commit df5a6c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Dapr.Actors/Communication/ActorStateResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Dapr.Actors.Communication
/// <summary>
/// Represents a response from fetching an actor state key.
/// </summary>
internal class ActorStateResponse<T>
class ActorStateResponse<T>
{
/// <summary>
/// Initializes a new instance of the <see cref="ActorStateResponse{T}"/> class.
Expand Down
18 changes: 14 additions & 4 deletions src/Dapr.Actors/Runtime/ActorStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public async Task<ConditionalValue<T>> TryGetStateAsync<T>(string stateName, Can
var stateMetadata = stateChangeTracker[stateName];

// Check if the property was marked as remove in the cache or is expired
if (stateMetadata.ChangeKind == StateChangeKind.Remove || stateMetadata.TTLExpireTime <= DateTime.UtcNow)
if (stateMetadata.ChangeKind == StateChangeKind.Remove || stateMetadata.TTLExpireTime <= DateTimeOffset.UtcNow)
{
return new ConditionalValue<T>(false, default);
}
Expand Down Expand Up @@ -539,7 +539,7 @@ private StateMetadata(object value, Type type, StateChangeKind changeKind, DateT
throw new ArgumentException("Cannot specify both TTLExpireTime and TTL");
}
if (ttl.HasValue) {
this.TTLExpireTime = DateTime.UtcNow.Add(ttl.Value);
this.TTLExpireTime = DateTimeOffset.UtcNow.Add(ttl.Value);
} else {
this.TTLExpireTime = ttlExpireTime;
}
Expand All @@ -553,9 +553,19 @@ private StateMetadata(object value, Type type, StateChangeKind changeKind, DateT

public DateTimeOffset? TTLExpireTime { get; set; }

public static StateMetadata Create<T>(T value, StateChangeKind changeKind, DateTimeOffset? ttlExpireTime = null, TimeSpan? ttl = null)
public static StateMetadata Create<T>(T value, StateChangeKind changeKind)
{
return new StateMetadata(value, typeof(T), changeKind, ttlExpireTime, ttl);
return new StateMetadata(value, typeof(T), changeKind);
}

public static StateMetadata Create<T>(T value, StateChangeKind changeKind, DateTimeOffset? ttlExpireTime)
{
return new StateMetadata(value, typeof(T), changeKind, ttlExpireTime: ttlExpireTime);
}

public static StateMetadata Create<T>(T value, StateChangeKind changeKind, TimeSpan? ttl)
{
return new StateMetadata(value, typeof(T), changeKind, ttl: ttl);
}

public static StateMetadata CreateForRemove()
Expand Down
4 changes: 2 additions & 2 deletions src/Dapr.Actors/Runtime/DaprStateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<ConditionalValue<ActorStateResponse<T>>> TryLoadStateAsync<T>(
var result = new ConditionalValue<ActorStateResponse<T>>(false, default);
var response = await this.daprInteractor.GetStateAsync(actorType, actorId, stateName, cancellationToken);

if (response.Value.Length != 0 && response.TTLExpireTime > DateTime.UtcNow)
if (response.Value.Length != 0 && response.TTLExpireTime > DateTimeOffset.UtcNow)
{
T typedResult;

Expand Down Expand Up @@ -135,7 +135,7 @@ private async Task DoStateChangesTransactionallyAsync(string actorType, string a
}

if (stateChange.TTLExpireTime.HasValue) {
var ttl = (int)Math.Ceiling((stateChange.TTLExpireTime.Value - DateTime.UtcNow).TotalSeconds);
var ttl = (int)Math.Ceiling((stateChange.TTLExpireTime.Value - DateTimeOffset.UtcNow).TotalSeconds);
writer.WriteString("ttlInSeconds", ttl.ToString());
}

Expand Down

0 comments on commit df5a6c0

Please sign in to comment.