Skip to content

Commit

Permalink
Retry PutAsync if table not found
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed May 4, 2022
1 parent 93325fb commit 1c260c4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/TableStorage/TableRepository`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,19 @@ pair.Value is DateOnly date ?
values[nameof(ITableEntity.PartitionKey)] = partitionKey;
values[nameof(ITableEntity.RowKey)] = rowKey;

var result = await table.UpsertEntityAsync(new TableEntity(values), UpdateMode, cancellation)
.ConfigureAwait(false);

try
{
await table.UpsertEntityAsync(new TableEntity(values), UpdateMode, cancellation)
.ConfigureAwait(false);
}
catch (RequestFailedException e) when (e.ErrorCode == "TableNotFound")
{
// Retry after ensuring table exists.
await table.CreateIfNotExistsAsync();
await table.UpsertEntityAsync(new TableEntity(values), UpdateMode, cancellation)
.ConfigureAwait(false);
}

return (await GetAsync(partitionKey, rowKey, cancellation).ConfigureAwait(false))!;
}

Expand Down

0 comments on commit 1c260c4

Please sign in to comment.