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