Skip to content

Commit 8fe9847

Browse files
authored
feat(sync-engine): add close() method to release database connections (#230)
1 parent 9ddcea5 commit 8fe9847

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

docs/typescript.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,11 @@ await sync.syncBackfill({
139139

140140
> **Note:**
141141
> For large Stripe accounts (more than 10,000 objects), it is recommended to write a script that loops through each day and sets the `created` date filters to the start and end of day. This avoids timeouts and memory issues when syncing large datasets.
142+
143+
## Cleanup
144+
145+
Call `close()` to release database connections when shutting down:
146+
147+
```ts
148+
await sync.close()
149+
```

packages/sync-engine/src/database/postgres.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,8 @@ export class PostgresClient {
229229
})
230230
return cleansed
231231
}
232+
233+
async close(): Promise<void> {
234+
await this.pool.end()
235+
}
232236
}

packages/sync-engine/src/stripeSync.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,10 @@ export class StripeSync {
17101710

17111711
return entities
17121712
}
1713+
1714+
async close(): Promise<void> {
1715+
await this.postgresClient.close()
1716+
}
17131717
}
17141718

17151719
function chunkArray<T>(array: T[], chunkSize: number): T[][] {

0 commit comments

Comments
 (0)