Skip to content

Commit 7479811

Browse files
committed
Changes from feedback
1 parent 3606455 commit 7479811

File tree

5 files changed

+16
-33
lines changed

5 files changed

+16
-33
lines changed

libraries/src/AWS.Lambda.Powertools.Idempotency/Idempotency.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,15 @@ public static void Configure(Action<IdempotencyBuilder> configurationAction)
9090
/// </summary>
9191
public class IdempotencyBuilder
9292
{
93-
/// <summary>
94-
/// Holds Idempotency options
95-
/// </summary>
96-
private IdempotencyOptions _options;
97-
/// <summary>
98-
/// Persistence Store
99-
/// </summary>
100-
private BasePersistenceStore _store;
10193
/// <summary>
10294
/// Exposes Idempotency options
10395
/// </summary>
104-
internal IdempotencyOptions Options => _options;
96+
internal IdempotencyOptions Options { get; private set; }
97+
10598
/// <summary>
10699
/// Exposes Persistence Store
107100
/// </summary>
108-
internal BasePersistenceStore Store => _store;
101+
internal BasePersistenceStore Store { get; private set; }
109102

110103
/// <summary>
111104
/// Set the persistence layer to use for storing the request and response
@@ -114,7 +107,7 @@ public class IdempotencyBuilder
114107
/// <returns>IdempotencyBuilder</returns>
115108
public IdempotencyBuilder WithPersistenceStore(BasePersistenceStore persistenceStore)
116109
{
117-
_store = persistenceStore;
110+
Store = persistenceStore;
118111
return this;
119112
}
120113

@@ -128,7 +121,7 @@ public IdempotencyBuilder UseDynamoDb(Action<DynamoDBPersistenceStoreBuilder> bu
128121
var builder =
129122
new DynamoDBPersistenceStoreBuilder();
130123
builderAction(builder);
131-
_store = builder.Build();
124+
Store = builder.Build();
132125
return this;
133126
}
134127

@@ -141,7 +134,7 @@ public IdempotencyBuilder UseDynamoDb(string tableName)
141134
{
142135
var builder =
143136
new DynamoDBPersistenceStoreBuilder();
144-
_store = builder.WithTableName(tableName).Build();
137+
Store = builder.WithTableName(tableName).Build();
145138
return this;
146139
}
147140

@@ -154,7 +147,7 @@ public IdempotencyBuilder WithOptions(Action<IdempotencyOptionsBuilder> builderA
154147
{
155148
var builder = new IdempotencyOptionsBuilder();
156149
builderAction(builder);
157-
_options = builder.Build();
150+
Options = builder.Build();
158151
return this;
159152
}
160153

@@ -165,7 +158,7 @@ public IdempotencyBuilder WithOptions(Action<IdempotencyOptionsBuilder> builderA
165158
/// <returns>IdempotencyBuilder</returns>
166159
public IdempotencyBuilder WithOptions(IdempotencyOptions options)
167160
{
168-
_options = options;
161+
Options = options;
169162
return this;
170163
}
171164
}

libraries/src/AWS.Lambda.Powertools.Idempotency/IdempotentAttribute.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
using System;
17+
using System.Linq;
1718
using System.Text.Json;
1819
using System.Threading.Tasks;
1920
using AspectInjector.Broker;
@@ -73,7 +74,8 @@ protected internal sealed override T WrapSync<T>(Func<object[], T> target, objec
7374
{
7475
return base.WrapSync(target, args, eventArgs);
7576
}
76-
var payload = JsonDocument.Parse(JsonSerializer.Serialize(args[0]));
77+
78+
var payload = args is not null && args.Any() ? JsonDocument.Parse(JsonSerializer.Serialize(args[0])) : null;
7779
if (payload == null)
7880
{
7981
throw new IdempotencyConfigurationException("Unable to get payload from the method. Ensure there is at least one parameter or that you use @IdempotencyKey");
@@ -105,7 +107,8 @@ protected internal sealed override async Task<T> WrapAsync<T>(
105107
{
106108
return await base.WrapAsync(target, args, eventArgs);
107109
}
108-
var payload = JsonDocument.Parse(JsonSerializer.Serialize(args[0]));
110+
111+
var payload = args is not null && args.Any() ? JsonDocument.Parse(JsonSerializer.Serialize(args[0])) : null;
109112
if (payload == null)
110113
{
111114
throw new IdempotencyConfigurationException("Unable to get payload from the method. Ensure there is at least one parameter or that you use @IdempotencyKey");

libraries/src/AWS.Lambda.Powertools.Idempotency/Persistence/BasePersistenceStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace AWS.Lambda.Powertools.Idempotency.Persistence;
2929
/// <summary>
3030
/// Persistence layer that will store the idempotency result.
3131
/// Base implementation. See <see cref="DynamoDBPersistenceStore"/> for an implementation (default one)
32-
/// Extend this class to use your own implementation (DocumentDB, Elasticache, ...)
32+
/// Extend this class to use your own implementation (DocumentDB, ElastiCache, ...)
3333
/// </summary>
3434
public abstract class BasePersistenceStore : IPersistenceStore
3535
{

libraries/src/AWS.Lambda.Powertools.Idempotency/Persistence/DataRecord.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,12 @@ public bool IsExpired(DateTimeOffset now)
7575
{
7676
return ExpiryTimestamp != 0 && now.ToUnixTimeSeconds() > ExpiryTimestamp;
7777
}
78-
7978

8079
/// <summary>
8180
/// Represents the <see cref="DataRecordStatus"/> Status
8281
/// </summary>
83-
public DataRecordStatus Status
84-
{
85-
get
86-
{
87-
var now = DateTimeOffset.UtcNow;
88-
if (IsExpired(now))
89-
{
90-
return DataRecordStatus.EXPIRED;
91-
}
92-
93-
return Enum.Parse<DataRecordStatus>(_status);
94-
}
95-
}
82+
public DataRecordStatus Status =>
83+
IsExpired(DateTimeOffset.UtcNow) ? DataRecordStatus.EXPIRED : Enum.Parse<DataRecordStatus>(_status);
9684

9785
/// <summary>
9886
/// Determines whether the specified DataRecord is equal to the current DataRecord

libraries/tests/AWS.Lambda.Powertools.Idempotency.Tests/Handlers/IdempotencyFunction.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public IdempotencyFunction(AmazonDynamoDBClient client)
3535
builder
3636
.WithOptions(optionsBuilder =>
3737
optionsBuilder
38-
//.WithUseLocalCache(true)
3938
.WithEventKeyJmesPath("powertools_json(Body).address")
4039
.WithExpiration(TimeSpan.FromSeconds(20)))
4140
.UseDynamoDb(storeBuilder =>

0 commit comments

Comments
 (0)