Skip to content

Commit

Permalink
feat(job-queue-plugin): Implement default cleanup of old BullMQ jobs
Browse files Browse the repository at this point in the history
Relates to #1425
  • Loading branch information
michaelbromley committed Sep 26, 2023
1 parent d3107fd commit 6c1d7bb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,19 @@ export class BullMQJobQueueStrategy implements InspectableJobQueueStrategy {

async init(injector: Injector): Promise<void> {
const options = injector.get<BullMQPluginOptions>(BULLMQ_PLUGIN_OPTIONS);
this.options = options;
this.options = {
...options,
workerOptions: {
removeOnComplete: options.workerOptions?.removeOnComplete ?? {
age: 60 * 60 * 24 * 30,
count: 5000,
},
removeOnFail: options.workerOptions?.removeOnFail ?? {
age: 60 * 60 * 24 * 30,
count: 5000,
},
},
};
this.connectionOptions =
options.connection ??
({
Expand Down
31 changes: 31 additions & 0 deletions packages/job-queue-plugin/src/bullmq/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,37 @@ import { BullMQPluginOptions } from './types';
* };
* ```
*
* ## Removing old jobs
*
* By default, BullMQ will keep completed jobs in the `completed` set and failed jobs in the `failed` set. Over time,
* these sets can grow very large. Since Vendure v2.1, the default behaviour is to remove jobs from these sets after
* 30 days or after a maximum of 5,000 completed or failed jobs.
*
* This can be configured using the `removeOnComplete` and `removeOnFail` options:
*
* @example
* ```ts
* const config: VendureConfig = {
* plugins: [
* BullMQJobQueuePlugin.init({
* workerOptions: {
* removeOnComplete: {
* count: 500,
* },
* removeOnFail: {
* age: 60 * 60 * 24 * 7, // 7 days
* count: 1000,
* },
* }
* }),
* ],
* };
* ```
*
* The `count` option specifies the maximum number of jobs to keep in the set, while the `age` option specifies the
* maximum age of a job in seconds. If both options are specified, then the jobs kept will be the ones that satisfy
* both properties.
*
* @docsCategory core plugins/JobQueuePlugin
*/
@VendurePlugin({
Expand Down

0 comments on commit 6c1d7bb

Please sign in to comment.