From df5a6c0212a2a7e8ac189d0b8ba53c34e4d1453e Mon Sep 17 00:00:00 2001 From: joshvanl Date: Fri, 27 Oct 2023 18:13:44 +0100 Subject: [PATCH] Address feedback Signed-off-by: joshvanl --- .../Communication/ActorStateResponse.cs | 2 +- src/Dapr.Actors/Runtime/ActorStateManager.cs | 18 ++++++++++++++---- src/Dapr.Actors/Runtime/DaprStateProvider.cs | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Dapr.Actors/Communication/ActorStateResponse.cs b/src/Dapr.Actors/Communication/ActorStateResponse.cs index e60878b6a..f75da0626 100644 --- a/src/Dapr.Actors/Communication/ActorStateResponse.cs +++ b/src/Dapr.Actors/Communication/ActorStateResponse.cs @@ -18,7 +18,7 @@ namespace Dapr.Actors.Communication /// /// Represents a response from fetching an actor state key. /// - internal class ActorStateResponse + class ActorStateResponse { /// /// Initializes a new instance of the class. diff --git a/src/Dapr.Actors/Runtime/ActorStateManager.cs b/src/Dapr.Actors/Runtime/ActorStateManager.cs index e25314566..0f1ac43e4 100644 --- a/src/Dapr.Actors/Runtime/ActorStateManager.cs +++ b/src/Dapr.Actors/Runtime/ActorStateManager.cs @@ -145,7 +145,7 @@ public async Task> TryGetStateAsync(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(false, default); } @@ -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; } @@ -553,9 +553,19 @@ private StateMetadata(object value, Type type, StateChangeKind changeKind, DateT public DateTimeOffset? TTLExpireTime { get; set; } - public static StateMetadata Create(T value, StateChangeKind changeKind, DateTimeOffset? ttlExpireTime = null, TimeSpan? ttl = null) + public static StateMetadata Create(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 value, StateChangeKind changeKind, DateTimeOffset? ttlExpireTime) + { + return new StateMetadata(value, typeof(T), changeKind, ttlExpireTime: ttlExpireTime); + } + + public static StateMetadata Create(T value, StateChangeKind changeKind, TimeSpan? ttl) + { + return new StateMetadata(value, typeof(T), changeKind, ttl: ttl); } public static StateMetadata CreateForRemove() diff --git a/src/Dapr.Actors/Runtime/DaprStateProvider.cs b/src/Dapr.Actors/Runtime/DaprStateProvider.cs index a6b81cd8f..d8d5ed2b5 100644 --- a/src/Dapr.Actors/Runtime/DaprStateProvider.cs +++ b/src/Dapr.Actors/Runtime/DaprStateProvider.cs @@ -49,7 +49,7 @@ public async Task>> TryLoadStateAsync( var result = new ConditionalValue>(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; @@ -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()); }