Skip to content

Commit 1cd3f68

Browse files
committed
Extract InternalCreateOrValidateTableAsync
1 parent a3c9659 commit 1cd3f68

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

src/FSharp.AWS.DynamoDB/TableContext.fs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,6 @@ type TableContext<'TRecord> internal
918918
return ()
919919
}
920920

921-
922921
member internal _.InternalDescribe() : Async<TableDescription> =
923922
let rec wait () = async {
924923
let! ct = Async.CancellationToken
@@ -933,7 +932,7 @@ type TableContext<'TRecord> internal
933932
}
934933
wait ()
935934

936-
member internal __.CreateOrValidateTableAsync(createThroughput) : Async<TableDescription> =
935+
member internal __.InternalProvision(?makeCreateTableRequest) : Async<TableDescription> =
937936
let (|Conflict|_|) (e : exn) =
938937
match e with
939938
| :? AmazonDynamoDBException as e when e.StatusCode = HttpStatusCode.Conflict -> Some()
@@ -950,11 +949,10 @@ type TableContext<'TRecord> internal
950949
|> invalidOp
951950
return desc
952951

953-
| Choice2Of2 (:? ResourceNotFoundException) when Option.isSome createThroughput ->
952+
| Choice2Of2 (:? ResourceNotFoundException) when Option.isSome makeCreateTableRequest ->
954953
let! ct = Async.CancellationToken
955-
let ctr = template.Info.Schemata.CreateCreateTableRequest(tableName, Option.get createThroughput)
956954
let! response =
957-
client.CreateTableAsync(ctr, ct)
955+
client.CreateTableAsync(makeCreateTableRequest.Value (), ct)
958956
|> Async.AwaitTaskCorrect
959957
|> Async.Catch
960958

@@ -975,48 +973,51 @@ type TableContext<'TRecord> internal
975973

976974
checkOrCreate 9 // up to 9 retries, i.e. 10 attempts before we let exception propagate
977975

978-
/// <summary>
979-
/// Asynchronously verify that the table exists and is compatible with record key schema.
980-
/// </summary>
981-
/// <param name="createIfNotExists">Create the table instance now instance if it does not exist. Defaults to false.</param>
982-
/// <param name="provisionedThroughput">Provisioned throughput for the table if newly created. Defaults to (10,10).</param>
983-
[<System.Obsolete("Please replace with either 1. VerifyTableAsync or 2. InitializeTableAsync")>]
984-
member __.VerifyTableAsync(?createIfNotExists : bool, ?provisionedThroughput : ProvisionedThroughput) : Async<unit> =
985-
let throughputIfCreate =
986-
if createIfNotExists = Some true then
987-
let throughput = match provisionedThroughput with Some p -> p | None -> ProvisionedThroughput(10L, 10L)
988-
Some throughput
989-
else None
990-
__.CreateOrValidateTableAsync(throughputIfCreate) |> Async.Ignore
976+
member internal _.InternalCreateTableRequest(throughput) =
977+
template.Info.Schemata.CreateCreateTableRequest(tableName, throughput)
978+
member internal t.InternalCreateOrValidateTableAsync(createThroughput) =
979+
t.InternalProvision(fun () -> t.InternalCreateTableRequest(createThroughput))
991980

992981
/// <summary>
993982
/// Asynchronously verify that the table exists and is compatible with record key schema, or throw.<br/>
994983
/// See also <c>InitializeTableAsync</c>, which performs the same check, but can create or re-provision the Table if required.
995984
/// </summary>
996985
member __.VerifyTableAsync() : Async<unit> =
997-
__.CreateOrValidateTableAsync(None) |> Async.Ignore
986+
__.InternalProvision() |> Async.Ignore
998987

999988
/// <summary>
1000989
/// Asynchronously verifies that the table exists and is compatible with record key schema, throwing if it is incompatible.<br/>
1001990
/// If the table is not present, it is provisioned, with the specified <c>throughput</c>.<br/>
1002991
/// See also <c>VerifyTableAsync</c>, which only verifies the Table is present and correct.
1003992
/// </summary>
1004993
/// <param name="throughput">Provisioned throughput to use for the table.</param>
1005-
member __.InitializeTableAsync(throughput : ProvisionedThroughput) : Async<unit> =
1006-
__.CreateOrValidateTableAsync(Some throughput) |> Async.Ignore
994+
member t.InitializeTableAsync(throughput : ProvisionedThroughput) : Async<unit> =
995+
t.InternalCreateOrValidateTableAsync(throughput) |> Async.Ignore
1007996

1008997
/// <summary>
1009998
/// Asynchronously verifies that the table exists and is compatible with record key schema, throwing if it is incompatible.<br/>
1010999
/// If the table is not present, it is provisioned, with the specified <c>throughput</c>.<br/>
10111000
/// If it is present, and the throughput is not as specified, uses <c>UpdateProvisionedThroughputAsync</c> to update it. <br/>
10121001
/// </summary>
10131002
/// <param name="throughput">Provisioned throughput to use for the table.</param>
1014-
member __.ProvisionTableAsync(throughput : ProvisionedThroughput) : Async<unit> = async {
1015-
let! desc = __.CreateOrValidateTableAsync(Some throughput)
1016-
let provisioned = desc.ProvisionedThroughput
1017-
if throughput.ReadCapacityUnits <> provisioned.ReadCapacityUnits
1018-
|| throughput.WriteCapacityUnits <> provisioned.WriteCapacityUnits then
1019-
do! __.UpdateProvisionedThroughputAsync(throughput) }
1003+
member t.ProvisionTableAsync(throughput : ProvisionedThroughput) : Async<unit> = async {
1004+
let! tableDescription = t.InternalCreateOrValidateTableAsync(throughput)
1005+
let provisioned = tableDescription.ProvisionedThroughput
1006+
if throughput.ReadCapacityUnits <> provisioned.ReadCapacityUnits || throughput.WriteCapacityUnits <> provisioned.WriteCapacityUnits then
1007+
do! t.UpdateProvisionedThroughputAsync(throughput) }
1008+
1009+
/// <summary>
1010+
/// Asynchronously verify that the table exists and is compatible with record key schema.
1011+
/// </summary>
1012+
/// <param name="createIfNotExists">Create the table instance now instance if it does not exist. Defaults to false.</param>
1013+
/// <param name="provisionedThroughput">Provisioned throughput for the table if newly created. Defaults to (10,10).</param>
1014+
[<System.Obsolete("Please replace with either 1. VerifyTableAsync or 2. InitializeTableAsync")>]
1015+
member t.VerifyTableAsync(?createIfNotExists : bool, ?provisionedThroughput : ProvisionedThroughput) : Async<unit> =
1016+
if createIfNotExists = Some true then
1017+
let throughput = match provisionedThroughput with Some p -> p | None -> ProvisionedThroughput(10L, 10L)
1018+
t.InitializeTableAsync(throughput)
1019+
else
1020+
t.VerifyTableAsync()
10201021

10211022
// Deprecated factory method, to be removed. Replaced with
10221023
// 1. TableContext<'T> ctor (synchronous)

0 commit comments

Comments
 (0)