refactor(core): Make executions pruning settings configurable (#7468)

This commit is contained in:
Iván Ovejero 2023-10-19 16:57:12 +02:00 committed by GitHub
parent c7c8048430
commit b50376cf52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 9 deletions

View file

@ -316,16 +316,30 @@ export const schema = {
env: 'EXECUTIONS_DATA_PRUNE', env: 'EXECUTIONS_DATA_PRUNE',
}, },
pruneDataMaxAge: { pruneDataMaxAge: {
doc: 'How old (hours) the finished execution data has to be to get deleted', doc: 'How old (hours) the finished execution data has to be to get soft-deleted',
format: Number, format: Number,
default: 336, default: 336,
env: 'EXECUTIONS_DATA_MAX_AGE', env: 'EXECUTIONS_DATA_MAX_AGE',
}, },
pruneDataInterval: { pruneDataHardDeleteBuffer: {
doc: 'How old (hours) the finished execution data has to be to get hard-deleted. By default, this buffer excludes recent executions as the user may need them while building a workflow.',
format: Number,
default: 1,
env: 'EXECUTIONS_DATA_HARD_DELETE_BUFFER',
},
pruneDataIntervals: {
hardDelete: {
doc: 'How often (minutes) execution data should be hard-deleted', doc: 'How often (minutes) execution data should be hard-deleted',
format: Number, format: Number,
default: 15, default: 15,
env: 'EXECUTIONS_DATA_PRUNE_INTERVAL', env: 'EXECUTIONS_DATA_PRUNE_HARD_DELETE_INTERVAL',
},
softDelete: {
doc: 'How often (minutes) execution data should be soft-deleted',
format: Number,
default: 60,
env: 'EXECUTIONS_DATA_PRUNE_SOFT_DELETE_INTERVAL',
},
}, },
// Additional pruning option to delete executions if total count exceeds the configured max. // Additional pruning option to delete executions if total count exceeds the configured max.

View file

@ -87,8 +87,8 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
}; };
private rates: Record<string, number> = { private rates: Record<string, number> = {
softDeletion: 1 * TIME.HOUR, softDeletion: config.getEnv('executions.pruneDataIntervals.softDelete') * TIME.MINUTE,
hardDeletion: config.getEnv('executions.pruneDataInterval') * TIME.MINUTE, hardDeletion: config.getEnv('executions.pruneDataIntervals.hardDelete') * TIME.MINUTE,
}; };
private isMainInstance = config.get('generic.instanceType') === 'main'; private isMainInstance = config.get('generic.instanceType') === 'main';
@ -523,9 +523,8 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
* Permanently delete all soft-deleted executions and their binary data, in batches. * Permanently delete all soft-deleted executions and their binary data, in batches.
*/ */
private async hardDelete() { private async hardDelete() {
// Find ids of all executions that were deleted over an hour ago
const date = new Date(); const date = new Date();
date.setHours(date.getHours() - 1); date.setHours(date.getHours() - config.getEnv('executions.pruneDataHardDeleteBuffer'));
const workflowIdsAndExecutionIds = ( const workflowIdsAndExecutionIds = (
await this.find({ await this.find({