import { BaseCoolQueue, CoolQueue } from '@cool-midway/task';
import { ILogger, IMidwayApplication, Inject, Logger } from '@midwayjs/core';
import { App } from '@midwayjs/decorator';
import { BalanceService } from '../service/balance';

@CoolQueue()
export class BalanceQueue extends BaseCoolQueue {
  @App()
  app: IMidwayApplication;

  @Inject()
  balanceService: BalanceService;

  @Logger()
  logger: ILogger;

  async data(job: any, done: any): Promise<void> {
    try {
      this.logger.info('更新余额', job.data);
      await this.balanceService.addBalance(job.data);
    } catch (err) {
      this.logger.error('更新余额失败', job.data, err.message);
    }
    done();
  }
}
