fix(contribution): run CDC sync in background to avoid blocking service startup

- Change await to .then() for cdcConsumer.start()
- Allows HTTP endpoints to be accessible during CDC sync

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-13 21:44:00 -08:00
parent 8199bc4d66
commit 703c12e9f6
1 changed files with 5 additions and 5 deletions

View File

@ -51,14 +51,14 @@ export class CDCEventDispatcher implements OnModuleInit {
this.handleAdoptionPostCommit.bind(this),
);
// 启动 CDC 消费者
try {
await this.cdcConsumer.start();
// 启动 CDC 消费者(非阻塞,在后台运行顺序同步)
// 不能 await否则会阻塞服务启动导致 HTTP 端点无法访问
this.cdcConsumer.start().then(() => {
this.logger.log('CDC event dispatcher started with transactional idempotency');
} catch (error) {
}).catch((error) => {
this.logger.error('Failed to start CDC event dispatcher', error);
// 不抛出错误,允许服务在没有 Kafka 的情况下启动(用于本地开发)
}
});
}
private async handleUserEvent(event: CDCEvent, tx: TransactionClient): Promise<void> {