Feature/improve handling of jobs (#1864)

* Improve handling of jobs
  * Remove jobs on complete
  * Refactor jobs removal

* Update changelog
This commit is contained in:
Thomas Kaul 2023-04-16 19:56:19 +02:00 committed by GitHub
parent 947460abdd
commit 654446f068
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 27 deletions

View File

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Changed
- Enabled the configuration to immediately remove queue jobs on complete
- Refactored the implementation of removing queue jobs
### Fixed ### Fixed
- Fixed the unique job ids of the gather asset profile process - Fixed the unique job ids of the gather asset profile process

View File

@ -4,7 +4,7 @@ import {
} from '@ghostfolio/common/config'; } from '@ghostfolio/common/config';
import { AdminJobs } from '@ghostfolio/common/interfaces'; import { AdminJobs } from '@ghostfolio/common/interfaces';
import { InjectQueue } from '@nestjs/bull'; import { InjectQueue } from '@nestjs/bull';
import { Injectable, Logger } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { JobStatus, Queue } from 'bull'; import { JobStatus, Queue } from 'bull';
@Injectable() @Injectable()
@ -23,14 +23,11 @@ export class QueueService {
}: { }: {
status?: JobStatus[]; status?: JobStatus[];
}) { }) {
const jobs = await this.dataGatheringQueue.getJobs(status); for (const statusItem of status) {
await this.dataGatheringQueue.clean(
for (const job of jobs) { 300,
try { statusItem === 'waiting' ? 'wait' : statusItem
await job.remove(); );
} catch (error) {
Logger.warn(error, 'QueueService');
}
} }
} }
@ -44,18 +41,23 @@ export class QueueService {
const jobs = await this.dataGatheringQueue.getJobs(status); const jobs = await this.dataGatheringQueue.getJobs(status);
const jobsWithState = await Promise.all( const jobsWithState = await Promise.all(
jobs.slice(0, limit).map(async (job) => { jobs
return { .filter((job) => {
attemptsMade: job.attemptsMade + 1, return job;
data: job.data, })
finishedOn: job.finishedOn, .slice(0, limit)
id: job.id, .map(async (job) => {
name: job.name, return {
stacktrace: job.stacktrace, attemptsMade: job.attemptsMade + 1,
state: await job.getState(), data: job.data,
timestamp: job.timestamp finishedOn: job.finishedOn,
}; id: job.id,
}) name: job.name,
stacktrace: job.stacktrace,
state: await job.getState(),
timestamp: job.timestamp
};
})
); );
return { return {

View File

@ -49,9 +49,7 @@ export const GATHER_ASSET_PROFILE_PROCESS_OPTIONS: JobOptions = {
type: 'exponential' type: 'exponential'
}, },
priority: DATA_GATHERING_QUEUE_PRIORITY_HIGH, priority: DATA_GATHERING_QUEUE_PRIORITY_HIGH,
removeOnComplete: { removeOnComplete: true
age: ms('2 weeks') / 1000
}
}; };
export const GATHER_HISTORICAL_MARKET_DATA_PROCESS = export const GATHER_HISTORICAL_MARKET_DATA_PROCESS =
'GATHER_HISTORICAL_MARKET_DATA'; 'GATHER_HISTORICAL_MARKET_DATA';
@ -62,9 +60,7 @@ export const GATHER_HISTORICAL_MARKET_DATA_PROCESS_OPTIONS: JobOptions = {
type: 'exponential' type: 'exponential'
}, },
priority: DATA_GATHERING_QUEUE_PRIORITY_LOW, priority: DATA_GATHERING_QUEUE_PRIORITY_LOW,
removeOnComplete: { removeOnComplete: true
age: ms('2 weeks') / 1000
}
}; };
export const HEADER_KEY_IMPERSONATION = 'Impersonation-Id'; export const HEADER_KEY_IMPERSONATION = 'Impersonation-Id';