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 { CACHE_TTL_INFINITE } from '@ghostfolio/common/config';
import {
PORTFOLIO_PROCESS_JOB_NAME,
PORTFOLIO_PROCESS_JOB_OPTIONS
PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME,
PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS
} from '@ghostfolio/common/config';
import {
DATE_FORMAT,
@ -1082,9 +1082,9 @@ export abstract class PortfolioCalculator {
data: {
userId: this.userId
},
name: PORTFOLIO_PROCESS_JOB_NAME,
name: PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME,
opts: {
...PORTFOLIO_PROCESS_JOB_OPTIONS
...PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS
// jobId
// priority
}
@ -1098,9 +1098,9 @@ export abstract class PortfolioCalculator {
data: {
userId: this.userId
},
name: PORTFOLIO_PROCESS_JOB_NAME,
name: PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME,
opts: {
...PORTFOLIO_PROCESS_JOB_OPTIONS
...PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS
// jobId
// priority
}

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

@ -1,5 +1,5 @@
import {
PORTFOLIO_PROCESS_JOB_NAME,
PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME,
PORTFOLIO_SNAPSHOT_QUEUE
} from '@ghostfolio/common/config';
@ -16,14 +16,14 @@ import { IPortfolioSnapshotQueueJob } from './interfaces/portfolio-snapshot-queu
export class PortfolioSnapshotProcessor {
public constructor() {}
@Process({ concurrency: 1, name: PORTFOLIO_PROCESS_JOB_NAME })
@Process({ concurrency: 1, name: PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME })
public async calculatePortfolioSnapshot(
job: Job<IPortfolioSnapshotQueueJob>
) {
try {
Logger.log(
`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
@ -31,10 +31,13 @@ export class PortfolioSnapshotProcessor {
Logger.log(
`Portfolio snapshot calculation of user ${job.data.userId} has been completed`,
`PortfolioProcessor (${PORTFOLIO_PROCESS_JOB_NAME})`
`PortfolioProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})`
);
} catch (error) {
Logger.error(error, `PortfolioProcessor (${PORTFOLIO_PROCESS_JOB_NAME})`);
Logger.error(
error,
`PortfolioProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})`
);
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
};
export const PORTFOLIO_PROCESS_JOB_NAME = 'PORTFOLIO';
export const PORTFOLIO_PROCESS_JOB_OPTIONS: JobOptions = {
export const PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME = 'PORTFOLIO';
export const PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS: JobOptions = {
// attempts: 12,
// backoff: {
// delay: ms('1 minute'),

Loading…
Cancel
Save