Skip to content

Commit

Permalink
fix(dynamodb): ensure table is ready
Browse files Browse the repository at this point in the history
Use the DescribeTable operation on a table to ensure that the table is ready.
  • Loading branch information
skyrpex committed Apr 4, 2024
1 parent f3dd991 commit 3e49820
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions dynamodb/dynamodb.extern.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ClientConfig {
export interface Client$Inflight {
readonly createTable: (input: Readonly<any>) => Promise<Readonly<any>>;
readonly deleteTable: (input: Readonly<any>) => Promise<Readonly<any>>;
readonly describeTable: (input: Readonly<any>) => Promise<Readonly<any>>;
readonly updateTimeToLive: (input: Readonly<any>) => Promise<Readonly<any>>;
}
export interface Credentials {
Expand Down
12 changes: 11 additions & 1 deletion dynamodb/dynamodb.sim.w
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Client {
inflight createTable(input: Json): Json;
inflight deleteTable(input: Json): Json;
inflight updateTimeToLive(input: Json): Json;
inflight describeTable(input: Json): Json;
}

class Util {
Expand Down Expand Up @@ -140,7 +141,7 @@ pub class Table_sim impl dynamodb_types.ITable {
})();

// delete the table if it already exists because we might be reusing the container
try { client.deleteTable({ TableName: tableName }); }
try { client.deleteTable({ TableName: tableName }); }
catch e { }

util.waitUntil(() => {
Expand All @@ -167,6 +168,15 @@ pub class Table_sim impl dynamodb_types.ITable {
});
}

// Wait until we can describe the table. This is
// to ensure that the table is ready to be used.
util.waitUntil(() => {
client.describeTable({
TableName: tableName,
});
return true;
});

state.set("tableName", tableName);
return true;
} catch error {
Expand Down

0 comments on commit 3e49820

Please sign in to comment.