mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
feat(core): Add configurable execution history limit (#5505)
* Prune execution data when more than cofnfigured limit * use stricter typings * use `pruneDataMaxCount` --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
parent
9a1e7b52f7
commit
db702932f3
|
@ -43,6 +43,7 @@ import {
|
|||
} from 'n8n-workflow';
|
||||
|
||||
import pick from 'lodash.pick';
|
||||
import type { FindOptionsWhere } from 'typeorm';
|
||||
import { LessThanOrEqual } from 'typeorm';
|
||||
import { DateUtils } from 'typeorm/util/DateUtils';
|
||||
import config from '@/config';
|
||||
|
@ -202,6 +203,7 @@ async function pruneExecutionData(this: WorkflowHooks): Promise<void> {
|
|||
throttling = true;
|
||||
const timeout = config.getEnv('executions.pruneDataTimeout'); // in seconds
|
||||
const maxAge = config.getEnv('executions.pruneDataMaxAge'); // in h
|
||||
const maxCount = config.getEnv('executions.pruneDataMaxCount');
|
||||
const date = new Date(); // today
|
||||
date.setHours(date.getHours() - maxAge);
|
||||
|
||||
|
@ -209,7 +211,21 @@ async function pruneExecutionData(this: WorkflowHooks): Promise<void> {
|
|||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const utcDate = DateUtils.mixedDateToUtcDatetimeString(date);
|
||||
|
||||
const toPrune = { stoppedAt: LessThanOrEqual(utcDate) };
|
||||
const toPrune: FindOptionsWhere<IExecutionFlattedDb> = { stoppedAt: LessThanOrEqual(utcDate) };
|
||||
|
||||
if (maxCount > 0) {
|
||||
const executions = await Db.collections.Execution.find({
|
||||
select: ['id'],
|
||||
skip: maxCount,
|
||||
take: 1,
|
||||
order: { id: 'DESC' },
|
||||
});
|
||||
|
||||
if (executions[0]) {
|
||||
toPrune.id = LessThanOrEqual(executions[0].id);
|
||||
}
|
||||
}
|
||||
|
||||
const isBinaryModeDefaultMode = config.getEnv('binaryDataManager.mode') === 'default';
|
||||
try {
|
||||
const executions = isBinaryModeDefaultMode
|
||||
|
|
|
@ -325,6 +325,16 @@ export const schema = {
|
|||
default: 3600,
|
||||
env: 'EXECUTIONS_DATA_PRUNE_TIMEOUT',
|
||||
},
|
||||
|
||||
// Additional pruning option to delete executions if total count exceeds the configured max.
|
||||
// Deletes the oldest entries first
|
||||
// Default is 0 = No limit
|
||||
pruneDataMaxCount: {
|
||||
doc: 'Maximum number of executions to keep in DB. Default 0 = no limit',
|
||||
format: Number,
|
||||
default: 0,
|
||||
env: 'EXECUTIONS_DATA_PRUNE_MAX_COUNT',
|
||||
},
|
||||
},
|
||||
|
||||
queue: {
|
||||
|
|
Loading…
Reference in a new issue