2022-05-07 20:00:51 +02:00
|
|
|
import {
|
|
|
|
DATA_GATHERING_QUEUE,
|
|
|
|
GATHER_ASSET_PROFILE_PROCESS
|
|
|
|
} from '@ghostfolio/common/config';
|
|
|
|
import { InjectQueue } from '@nestjs/bull';
|
2021-04-13 21:53:58 +02:00
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
import { Cron, CronExpression } from '@nestjs/schedule';
|
2022-05-07 20:00:51 +02:00
|
|
|
import { Queue } from 'bull';
|
2021-04-13 21:53:58 +02:00
|
|
|
|
|
|
|
import { DataGatheringService } from './data-gathering.service';
|
|
|
|
import { ExchangeRateDataService } from './exchange-rate-data.service';
|
2022-02-16 21:17:11 +01:00
|
|
|
import { TwitterBotService } from './twitter-bot/twitter-bot.service';
|
2021-04-13 21:53:58 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class CronService {
|
|
|
|
public constructor(
|
2022-05-07 20:00:51 +02:00
|
|
|
@InjectQueue(DATA_GATHERING_QUEUE)
|
|
|
|
private readonly dataGatheringQueue: Queue,
|
2021-04-13 21:53:58 +02:00
|
|
|
private readonly dataGatheringService: DataGatheringService,
|
2022-02-16 21:17:11 +01:00
|
|
|
private readonly exchangeRateDataService: ExchangeRateDataService,
|
|
|
|
private readonly twitterBotService: TwitterBotService
|
2021-04-13 21:53:58 +02:00
|
|
|
) {}
|
|
|
|
|
|
|
|
@Cron(CronExpression.EVERY_MINUTE)
|
|
|
|
public async runEveryMinute() {
|
|
|
|
await this.dataGatheringService.gather7Days();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Cron(CronExpression.EVERY_12_HOURS)
|
|
|
|
public async runEveryTwelveHours() {
|
|
|
|
await this.exchangeRateDataService.loadCurrencies();
|
|
|
|
}
|
2021-10-24 10:49:17 +02:00
|
|
|
|
2022-02-17 21:31:08 +01:00
|
|
|
@Cron(CronExpression.EVERY_DAY_AT_5PM)
|
|
|
|
public async runEveryDayAtFivePM() {
|
2022-02-16 21:17:11 +01:00
|
|
|
this.twitterBotService.tweetFearAndGreedIndex();
|
|
|
|
}
|
|
|
|
|
2021-10-24 10:49:17 +02:00
|
|
|
@Cron(CronExpression.EVERY_WEEKEND)
|
|
|
|
public async runEveryWeekend() {
|
2022-05-07 20:00:51 +02:00
|
|
|
const uniqueAssets = await this.dataGatheringService.getUniqueAssets();
|
|
|
|
|
|
|
|
for (const { dataSource, symbol } of uniqueAssets) {
|
|
|
|
await this.dataGatheringQueue.add(GATHER_ASSET_PROFILE_PROCESS, {
|
|
|
|
dataSource,
|
|
|
|
symbol
|
|
|
|
});
|
|
|
|
}
|
2021-10-24 10:49:17 +02:00
|
|
|
}
|
2021-04-13 21:53:58 +02:00
|
|
|
}
|