feat: enforce signature-scoped drainage authorization before SMS submission
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { Injectable, Logger, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
||||
import { SendChainService } from './send-chain.service';
|
||||
|
||||
@Injectable()
|
||||
export class DrainageReceiptRecoveryService implements OnModuleInit, OnModuleDestroy {
|
||||
private timer?: ReturnType<typeof setInterval>;
|
||||
private running = false;
|
||||
private readonly logger = new Logger(DrainageReceiptRecoveryService.name);
|
||||
constructor(private readonly sendChain: SendChainService) {}
|
||||
onModuleInit() {
|
||||
if (['api', 'callback', 'outbox'].includes(process.env.CMPP_PROCESS_ROLE ?? 'all')) return;
|
||||
this.timer = setInterval(() => void this.scan(), 10000);
|
||||
this.timer.unref?.();
|
||||
}
|
||||
async scan() {
|
||||
if (this.running) return;
|
||||
this.running = true;
|
||||
try {
|
||||
await this.sendChain.recoverDrainageFailureReceipts();
|
||||
} catch (error) {
|
||||
this.logger.error(`引流拦截回执恢复失败: ${String(error)}`);
|
||||
} finally {
|
||||
this.running = false;
|
||||
}
|
||||
}
|
||||
onModuleDestroy() {
|
||||
if (this.timer) clearInterval(this.timer);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user