2022-05-07 20:00:51 +02:00
|
|
|
import {
|
2022-06-11 13:40:15 +02:00
|
|
|
GATHER_ASSET_PROFILE_PROCESS,
|
|
|
|
GATHER_ASSET_PROFILE_PROCESS_OPTIONS
|
2022-05-07 20:00:51 +02:00
|
|
|
} from '@ghostfolio/common/config';
|
2021-04-13 21:53:58 +02:00
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
import { Cron, CronExpression } from '@nestjs/schedule';
|
|
|
|
|
|
|
|
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 {
|
2022-12-28 09:31:46 +01:00
|
|
|
private static readonly EVERY_SUNDAY_AT_LUNCH_TIME = '0 12 * * 0';
|
|
|
|
|
2021-04-13 21:53:58 +02:00
|
|
|
public constructor(
|
|
|
|
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
|
|
|
) {}
|
|
|
|
|
2023-01-17 10:04:03 +01:00
|
|
|
@Cron(CronExpression.EVERY_4_HOURS)
|
|
|
|
public async runEveryFourHours() {
|
2023-04-14 07:01:34 +02:00
|
|
|
// await this.dataGatheringService.gather7Days();
|
2021-04-13 21:53:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Cron(CronExpression.EVERY_12_HOURS)
|
|
|
|
public async runEveryTwelveHours() {
|
|
|
|
await this.exchangeRateDataService.loadCurrencies();
|
2023-04-14 07:01:34 +02:00
|
|
|
await this.dataGatheringService.gather7Days();
|
2021-04-13 21:53:58 +02:00
|
|
|
}
|
2021-10-24 10:49:17 +02:00
|
|
|
|
2022-02-17 21:31:08 +01:00
|
|
|
@Cron(CronExpression.EVERY_DAY_AT_5PM)
|
2022-12-28 09:31:46 +01:00
|
|
|
public async runEveryDayAtFivePm() {
|
2022-02-16 21:17:11 +01:00
|
|
|
this.twitterBotService.tweetFearAndGreedIndex();
|
|
|
|
}
|
|
|
|
|
2022-12-28 09:31:46 +01:00
|
|
|
@Cron(CronService.EVERY_SUNDAY_AT_LUNCH_TIME)
|
|
|
|
public async runEverySundayAtTwelvePm() {
|
2022-05-07 20:00:51 +02:00
|
|
|
const uniqueAssets = await this.dataGatheringService.getUniqueAssets();
|
|
|
|
|
|
|
|
for (const { dataSource, symbol } of uniqueAssets) {
|
2022-06-11 13:40:15 +02:00
|
|
|
await this.dataGatheringService.addJobToQueue(
|
|
|
|
GATHER_ASSET_PROFILE_PROCESS,
|
|
|
|
{
|
|
|
|
dataSource,
|
|
|
|
symbol
|
|
|
|
},
|
|
|
|
GATHER_ASSET_PROFILE_PROCESS_OPTIONS
|
|
|
|
);
|
2022-05-07 20:00:51 +02:00
|
|
|
}
|
2021-10-24 10:49:17 +02:00
|
|
|
}
|
2021-04-13 21:53:58 +02:00
|
|
|
}
|