fix(contribution): run CDC sync in background to allow API access during sync

Change CDC consumer startup from blocking await to non-blocking .then()
so HTTP server starts immediately and /health/cdc-sync API is accessible
for deploy script to poll sync status.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-13 21:50:59 -08:00
parent 5a4970d7d9
commit d968efcad4
1 changed files with 11 additions and 8 deletions

View File

@ -51,14 +51,17 @@ export class CDCEventDispatcher implements OnModuleInit {
this.handleAdoptionPostCommit.bind(this), this.handleAdoptionPostCommit.bind(this),
); );
// 启动 CDC 消费者 // 非阻塞启动 CDC 消费者
try { // 让 HTTP 服务器先启动CDC 同步在后台进行
await this.cdcConsumer.start(); // 脚本通过 /health/cdc-sync API 轮询同步状态
this.logger.log('CDC event dispatcher started with transactional idempotency'); this.cdcConsumer.start()
} catch (error) { .then(() => {
this.logger.error('Failed to start CDC event dispatcher', error); this.logger.log('CDC event dispatcher started with transactional idempotency');
// 不抛出错误,允许服务在没有 Kafka 的情况下启动(用于本地开发) })
} .catch((error) => {
this.logger.error('Failed to start CDC event dispatcher', error);
// 不抛出错误,允许服务在没有 Kafka 的情况下启动(用于本地开发)
});
} }
private async handleUserEvent(event: CDCEvent, tx: TransactionClient): Promise<void> { private async handleUserEvent(event: CDCEvent, tx: TransactionClient): Promise<void> {