From b7c8cdd249d237bbcd97ddd6294dbb92cb2aa8d3 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 18 Jan 2026 08:28:48 -0800 Subject: [PATCH] =?UTF-8?q?fix(trading):=20=E9=94=80=E6=AF=81=E5=92=8C?= =?UTF-8?q?=E5=BF=AB=E7=85=A7=E5=8F=AA=E5=9C=A8=E4=BA=A4=E6=98=93=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=BF=80=E6=B4=BB=E6=97=B6=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - BurnScheduler 检查 trading_configs.isActive 状态 - 交易系统未激活时跳过每分钟销毁和价格快照 - 交易系统未激活时跳过每小时状态日志 Co-Authored-By: Claude Opus 4.5 --- .../application/schedulers/burn.scheduler.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/services/trading-service/src/application/schedulers/burn.scheduler.ts b/backend/services/trading-service/src/application/schedulers/burn.scheduler.ts index af88014e..10faaccb 100644 --- a/backend/services/trading-service/src/application/schedulers/burn.scheduler.ts +++ b/backend/services/trading-service/src/application/schedulers/burn.scheduler.ts @@ -3,6 +3,7 @@ import { Cron, CronExpression } from '@nestjs/schedule'; import { BurnService } from '../services/burn.service'; import { PriceService } from '../services/price.service'; import { RedisService } from '../../infrastructure/redis/redis.service'; +import { TradingConfigRepository } from '../../infrastructure/persistence/repositories/trading-config.repository'; @Injectable() export class BurnScheduler implements OnModuleInit { @@ -12,6 +13,7 @@ export class BurnScheduler implements OnModuleInit { private readonly burnService: BurnService, private readonly priceService: PriceService, private readonly redis: RedisService, + private readonly tradingConfigRepository: TradingConfigRepository, ) {} async onModuleInit() { @@ -32,10 +34,19 @@ export class BurnScheduler implements OnModuleInit { * * 注意:销毁和快照必须在同一个任务中顺序执行, * 确保快照总是捕获销毁后的最新价格,避免K线出现价格不变的情况 + * + * 只有当交易系统激活时才执行销毁和快照 */ @Cron(CronExpression.EVERY_MINUTE) async executeMinuteBurnAndSnapshot(): Promise { try { + // 检查交易系统是否激活 + const config = await this.tradingConfigRepository.getConfig(); + if (!config || !config.isActive) { + // 交易系统未激活,跳过销毁和快照 + return; + } + // 1. 先执行销毁 const burnAmount = await this.burnService.executeMinuteBurn(); if (!burnAmount.isZero()) { @@ -71,11 +82,17 @@ export class BurnScheduler implements OnModuleInit { } /** - * 每小时记录销毁状态日志 + * 每小时记录销毁状态日志(只在交易系统激活时记录) */ @Cron('0 * * * *') // 每小时整点 async logBurnStatus(): Promise { try { + // 检查交易系统是否激活 + const config = await this.tradingConfigRepository.getConfig(); + if (!config || !config.isActive) { + return; + } + const status = await this.burnService.getBurnStatus(); this.logger.log( `Burn status: burned=${status.totalBurned}, ` +