|
@ -1,6 +1,7 @@ |
|
|
import { |
|
|
import { |
|
|
GATHER_ASSET_PROFILE_PROCESS, |
|
|
GATHER_ASSET_PROFILE_PROCESS, |
|
|
GATHER_ASSET_PROFILE_PROCESS_OPTIONS |
|
|
GATHER_ASSET_PROFILE_PROCESS_OPTIONS, |
|
|
|
|
|
PROPERTY_IS_DATA_GATHERING_ENABLED |
|
|
} from '@ghostfolio/common/config'; |
|
|
} from '@ghostfolio/common/config'; |
|
|
import { getAssetProfileIdentifier } from '@ghostfolio/common/helper'; |
|
|
import { getAssetProfileIdentifier } from '@ghostfolio/common/helper'; |
|
|
import { Injectable } from '@nestjs/common'; |
|
|
import { Injectable } from '@nestjs/common'; |
|
@ -8,6 +9,7 @@ import { Cron, CronExpression } from '@nestjs/schedule'; |
|
|
|
|
|
|
|
|
import { DataGatheringService } from './data-gathering/data-gathering.service'; |
|
|
import { DataGatheringService } from './data-gathering/data-gathering.service'; |
|
|
import { ExchangeRateDataService } from './exchange-rate-data/exchange-rate-data.service'; |
|
|
import { ExchangeRateDataService } from './exchange-rate-data/exchange-rate-data.service'; |
|
|
|
|
|
import { PropertyService } from './property/property.service'; |
|
|
import { TwitterBotService } from './twitter-bot/twitter-bot.service'; |
|
|
import { TwitterBotService } from './twitter-bot/twitter-bot.service'; |
|
|
|
|
|
|
|
|
@Injectable() |
|
|
@Injectable() |
|
@ -17,12 +19,15 @@ export class CronService { |
|
|
public constructor( |
|
|
public constructor( |
|
|
private readonly dataGatheringService: DataGatheringService, |
|
|
private readonly dataGatheringService: DataGatheringService, |
|
|
private readonly exchangeRateDataService: ExchangeRateDataService, |
|
|
private readonly exchangeRateDataService: ExchangeRateDataService, |
|
|
|
|
|
private readonly propertyService: PropertyService, |
|
|
private readonly twitterBotService: TwitterBotService |
|
|
private readonly twitterBotService: TwitterBotService |
|
|
) {} |
|
|
) {} |
|
|
|
|
|
|
|
|
@Cron(CronExpression.EVERY_HOUR) |
|
|
@Cron(CronExpression.EVERY_HOUR) |
|
|
public async runEveryHour() { |
|
|
public async runEveryHour() { |
|
|
await this.dataGatheringService.gather7Days(); |
|
|
if (await this.isDataGatheringEnabled()) { |
|
|
|
|
|
await this.dataGatheringService.gather7Days(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Cron(CronExpression.EVERY_12_HOURS) |
|
|
@Cron(CronExpression.EVERY_12_HOURS) |
|
@ -37,22 +42,32 @@ export class CronService { |
|
|
|
|
|
|
|
|
@Cron(CronService.EVERY_SUNDAY_AT_LUNCH_TIME) |
|
|
@Cron(CronService.EVERY_SUNDAY_AT_LUNCH_TIME) |
|
|
public async runEverySundayAtTwelvePm() { |
|
|
public async runEverySundayAtTwelvePm() { |
|
|
const uniqueAssets = await this.dataGatheringService.getUniqueAssets(); |
|
|
if (await this.isDataGatheringEnabled()) { |
|
|
|
|
|
const uniqueAssets = await this.dataGatheringService.getUniqueAssets(); |
|
|
await this.dataGatheringService.addJobsToQueue( |
|
|
|
|
|
uniqueAssets.map(({ dataSource, symbol }) => { |
|
|
await this.dataGatheringService.addJobsToQueue( |
|
|
return { |
|
|
uniqueAssets.map(({ dataSource, symbol }) => { |
|
|
data: { |
|
|
return { |
|
|
dataSource, |
|
|
data: { |
|
|
symbol |
|
|
dataSource, |
|
|
}, |
|
|
symbol |
|
|
name: GATHER_ASSET_PROFILE_PROCESS, |
|
|
}, |
|
|
opts: { |
|
|
name: GATHER_ASSET_PROFILE_PROCESS, |
|
|
...GATHER_ASSET_PROFILE_PROCESS_OPTIONS, |
|
|
opts: { |
|
|
jobId: getAssetProfileIdentifier({ dataSource, symbol }) |
|
|
...GATHER_ASSET_PROFILE_PROCESS_OPTIONS, |
|
|
} |
|
|
jobId: getAssetProfileIdentifier({ dataSource, symbol }) |
|
|
}; |
|
|
} |
|
|
}) |
|
|
}; |
|
|
); |
|
|
}) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async isDataGatheringEnabled() { |
|
|
|
|
|
return (await this.propertyService.getByKey( |
|
|
|
|
|
PROPERTY_IS_DATA_GATHERING_ENABLED |
|
|
|
|
|
)) === false |
|
|
|
|
|
? false |
|
|
|
|
|
: true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|