Browse Source

Refactoring

pull/3725/head
Thomas Kaul 12 months ago
parent
commit
608bd82015
  1. 12
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  2. 13
      apps/api/src/services/portfolio-snapshot/portfolio-snapshot.processor.ts
  3. 4
      libs/common/src/lib/config.ts

12
apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

@ -14,8 +14,8 @@ import { PortfolioSnapshotService } from '@ghostfolio/api/services/portfolio-sna
import { getIntervalFromDateRange } from '@ghostfolio/common/calculation-helper'; import { getIntervalFromDateRange } from '@ghostfolio/common/calculation-helper';
import { CACHE_TTL_INFINITE } from '@ghostfolio/common/config'; import { CACHE_TTL_INFINITE } from '@ghostfolio/common/config';
import { import {
PORTFOLIO_PROCESS_JOB_NAME, PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME,
PORTFOLIO_PROCESS_JOB_OPTIONS PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS
} from '@ghostfolio/common/config'; } from '@ghostfolio/common/config';
import { import {
DATE_FORMAT, DATE_FORMAT,
@ -1082,9 +1082,9 @@ export abstract class PortfolioCalculator {
data: { data: {
userId: this.userId userId: this.userId
}, },
name: PORTFOLIO_PROCESS_JOB_NAME, name: PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME,
opts: { opts: {
...PORTFOLIO_PROCESS_JOB_OPTIONS ...PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS
// jobId // jobId
// priority // priority
} }
@ -1098,9 +1098,9 @@ export abstract class PortfolioCalculator {
data: { data: {
userId: this.userId userId: this.userId
}, },
name: PORTFOLIO_PROCESS_JOB_NAME, name: PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME,
opts: { opts: {
...PORTFOLIO_PROCESS_JOB_OPTIONS ...PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS
// jobId // jobId
// priority // priority
} }

13
apps/api/src/services/portfolio-snapshot/portfolio-snapshot.processor.ts

@ -1,5 +1,5 @@
import { import {
PORTFOLIO_PROCESS_JOB_NAME, PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME,
PORTFOLIO_SNAPSHOT_QUEUE PORTFOLIO_SNAPSHOT_QUEUE
} from '@ghostfolio/common/config'; } from '@ghostfolio/common/config';
@ -16,14 +16,14 @@ import { IPortfolioSnapshotQueueJob } from './interfaces/portfolio-snapshot-queu
export class PortfolioSnapshotProcessor { export class PortfolioSnapshotProcessor {
public constructor() {} public constructor() {}
@Process({ concurrency: 1, name: PORTFOLIO_PROCESS_JOB_NAME }) @Process({ concurrency: 1, name: PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME })
public async calculatePortfolioSnapshot( public async calculatePortfolioSnapshot(
job: Job<IPortfolioSnapshotQueueJob> job: Job<IPortfolioSnapshotQueueJob>
) { ) {
try { try {
Logger.log( Logger.log(
`Portfolio snapshot calculation of user ${job.data.userId} has been started`, `Portfolio snapshot calculation of user ${job.data.userId} has been started`,
`PortfolioProcessor (${PORTFOLIO_PROCESS_JOB_NAME})` `PortfolioProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})`
); );
// TODO: Do something // TODO: Do something
@ -31,10 +31,13 @@ export class PortfolioSnapshotProcessor {
Logger.log( Logger.log(
`Portfolio snapshot calculation of user ${job.data.userId} has been completed`, `Portfolio snapshot calculation of user ${job.data.userId} has been completed`,
`PortfolioProcessor (${PORTFOLIO_PROCESS_JOB_NAME})` `PortfolioProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})`
); );
} catch (error) { } catch (error) {
Logger.error(error, `PortfolioProcessor (${PORTFOLIO_PROCESS_JOB_NAME})`); Logger.error(
error,
`PortfolioProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})`
);
throw new Error(error); throw new Error(error);
} }

4
libs/common/src/lib/config.ts

@ -88,8 +88,8 @@ export const GATHER_HISTORICAL_MARKET_DATA_PROCESS_JOB_OPTIONS: JobOptions = {
}, },
removeOnComplete: true removeOnComplete: true
}; };
export const PORTFOLIO_PROCESS_JOB_NAME = 'PORTFOLIO'; export const PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME = 'PORTFOLIO';
export const PORTFOLIO_PROCESS_JOB_OPTIONS: JobOptions = { export const PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS: JobOptions = {
// attempts: 12, // attempts: 12,
// backoff: { // backoff: {
// delay: ms('1 minute'), // delay: ms('1 minute'),

Loading…
Cancel
Save