Skip to content

Commit 7766b91

Browse files
authored
fix(rdb): add read replica and snapshot waiters (#231)
1 parent 38e2217 commit 7766b91

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

packages/clients/src/api/rdb/v1/api.gen.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
DATABASE_BACKUP_TRANSIENT_STATUSES,
1414
INSTANCE_LOG_TRANSIENT_STATUSES,
1515
INSTANCE_TRANSIENT_STATUSES,
16+
READ_REPLICA_TRANSIENT_STATUSES,
17+
SNAPSHOT_TRANSIENT_STATUSES,
1618
} from './content.gen'
1719
import {
1820
marshalAddInstanceACLRulesRequest,
@@ -757,6 +759,28 @@ export class RdbV1GenAPI extends API {
757759
unmarshalReadReplica,
758760
)
759761

762+
/**
763+
* Waits for {@link ReadReplica} to be in a final state.
764+
*
765+
* @param request - The request {@link GetReadReplicaRequest}
766+
* @param options - The waiting options
767+
* @returns A Promise of ReadReplica
768+
*/
769+
waitForReadReplica = (
770+
request: Readonly<GetReadReplicaRequest>,
771+
options?: Readonly<WaitForOptions<ReadReplica>>,
772+
) =>
773+
waitForResource(
774+
options?.stop ??
775+
(res =>
776+
Promise.resolve(
777+
!READ_REPLICA_TRANSIENT_STATUSES.includes(res.status),
778+
)),
779+
this.getReadReplica,
780+
request,
781+
options,
782+
)
783+
760784
/**
761785
* Delete a read replica
762786
*
@@ -1446,6 +1470,26 @@ export class RdbV1GenAPI extends API {
14461470
unmarshalSnapshot,
14471471
)
14481472

1473+
/**
1474+
* Waits for {@link Snapshot} to be in a final state.
1475+
*
1476+
* @param request - The request {@link GetSnapshotRequest}
1477+
* @param options - The waiting options
1478+
* @returns A Promise of Snapshot
1479+
*/
1480+
waitForSnapshot = (
1481+
request: Readonly<GetSnapshotRequest>,
1482+
options?: Readonly<WaitForOptions<Snapshot>>,
1483+
) =>
1484+
waitForResource(
1485+
options?.stop ??
1486+
(res =>
1487+
Promise.resolve(!SNAPSHOT_TRANSIENT_STATUSES.includes(res.status))),
1488+
this.getSnapshot,
1489+
request,
1490+
options,
1491+
)
1492+
14491493
/**
14501494
* Create an instance snapshot
14511495
*

packages/clients/src/api/rdb/v1/content.gen.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type {
55
InstanceLogStatus,
66
InstanceStatus,
77
MaintenanceStatus,
8+
ReadReplicaStatus,
9+
SnapshotStatus,
810
} from './types.gen'
911

1012
/** Lists transient statutes of the enum {@link DatabaseBackupStatus}. */
@@ -32,3 +34,18 @@ export const INSTANCE_TRANSIENT_STATUSES: InstanceStatus[] = [
3234

3335
/** Lists transient statutes of the enum {@link MaintenanceStatus}. */
3436
export const MAINTENANCE_TRANSIENT_STATUSES: MaintenanceStatus[] = ['pending']
37+
38+
/** Lists transient statutes of the enum {@link ReadReplicaStatus}. */
39+
export const READ_REPLICA_TRANSIENT_STATUSES: ReadReplicaStatus[] = [
40+
'provisioning',
41+
'initializing',
42+
'deleting',
43+
'configuring',
44+
]
45+
46+
/** Lists transient statutes of the enum {@link SnapshotStatus}. */
47+
export const SNAPSHOT_TRANSIENT_STATUSES: SnapshotStatus[] = [
48+
'creating',
49+
'restoring',
50+
'deleting',
51+
]

0 commit comments

Comments
 (0)