feat(mining-admin): implement transactional idempotent consumer for 100% exactly-once semantics
- Use Prisma $transaction with Serializable isolation level - Insert idempotency record FIRST, then execute business logic - Unique constraint violation (P2002) indicates duplicate event - All operations atomic - either fully commit or fully rollback - Modified all handlers to accept transaction client parameter - Removed old non-atomic isEventProcessed/recordProcessedEvent methods This ensures 100% data consistency for CDC synchronization, which is critical for financial data where any error is catastrophic. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
577f626972
commit
70135938c4
|
|
@ -48,6 +48,8 @@ export interface ServiceEvent {
|
|||
|
||||
export type CdcHandler = (event: CdcEvent) => Promise<void>;
|
||||
export type ServiceEventHandler = (event: ServiceEvent) => Promise<void>;
|
||||
/** 支持事务的 handler 类型,tx 参数为 Prisma 事务客户端 */
|
||||
export type TransactionalServiceEventHandler = (event: ServiceEvent, tx: any) => Promise<void>;
|
||||
|
||||
@Injectable()
|
||||
export class CdcConsumerService implements OnModuleInit, OnModuleDestroy {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue