mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 21:19:43 -08:00
fix(core): Mark binary data to be deleted when pruning executions (#4713)
* Mark binary data to be deleted when pruning executions * eslint * make pruneExecutionData async Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
parent
95b97078e8
commit
78c66f16d6
|
@ -193,7 +193,7 @@ export function executeErrorWorkflow(
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
let throttling = false;
|
let throttling = false;
|
||||||
function pruneExecutionData(this: WorkflowHooks): void {
|
async function pruneExecutionData(this: WorkflowHooks): Promise<void> {
|
||||||
if (!throttling) {
|
if (!throttling) {
|
||||||
Logger.verbose('Pruning execution data from database');
|
Logger.verbose('Pruning execution data from database');
|
||||||
|
|
||||||
|
@ -207,16 +207,20 @@ function pruneExecutionData(this: WorkflowHooks): void {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
const utcDate = DateUtils.mixedDateToUtcDatetimeString(date);
|
const utcDate = DateUtils.mixedDateToUtcDatetimeString(date);
|
||||||
|
|
||||||
// throttle just on success to allow for self healing on failure
|
try {
|
||||||
Db.collections.Execution.delete({ stoppedAt: LessThanOrEqual(utcDate) })
|
const executions = await Db.collections.Execution.find({
|
||||||
.then((data) =>
|
stoppedAt: LessThanOrEqual(utcDate),
|
||||||
|
});
|
||||||
|
await Db.collections.Execution.delete({ stoppedAt: LessThanOrEqual(utcDate) });
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
throttling = false;
|
throttling = false;
|
||||||
}, timeout * 1000),
|
}, timeout * 1000);
|
||||||
)
|
// Mark binary data for deletion for all executions
|
||||||
.catch((error) => {
|
await BinaryDataManager.getInstance().markDataForDeletionByExecutionIds(
|
||||||
|
executions.map(({ id }) => id.toString()),
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
ErrorReporter.error(error);
|
ErrorReporter.error(error);
|
||||||
|
|
||||||
throttling = false;
|
throttling = false;
|
||||||
Logger.error(
|
Logger.error(
|
||||||
`Failed pruning execution data from database for execution ID ${this.executionId} (hookFunctionsSave)`,
|
`Failed pruning execution data from database for execution ID ${this.executionId} (hookFunctionsSave)`,
|
||||||
|
@ -227,7 +231,7 @@ function pruneExecutionData(this: WorkflowHooks): void {
|
||||||
workflowId: this.workflowData.id,
|
workflowId: this.workflowData.id,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,7 +495,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||||
|
|
||||||
// Prune old execution data
|
// Prune old execution data
|
||||||
if (config.getEnv('executions.pruneData')) {
|
if (config.getEnv('executions.pruneData')) {
|
||||||
pruneExecutionData.call(this);
|
await pruneExecutionData.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const isManualMode = [this.mode, parentProcessMode].includes('manual');
|
const isManualMode = [this.mode, parentProcessMode].includes('manual');
|
||||||
|
|
|
@ -144,6 +144,18 @@ export class BinaryDataManager {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async markDataForDeletionByExecutionIds(executionIds: string[]): Promise<void> {
|
||||||
|
if (this.managers[this.binaryDataMode]) {
|
||||||
|
return Promise.all(
|
||||||
|
executionIds.map(async (id) =>
|
||||||
|
this.managers[this.binaryDataMode].markDataForDeletionByExecutionId(id),
|
||||||
|
),
|
||||||
|
).then(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
async persistBinaryDataForExecutionId(executionId: string): Promise<void> {
|
async persistBinaryDataForExecutionId(executionId: string): Promise<void> {
|
||||||
if (this.managers[this.binaryDataMode]) {
|
if (this.managers[this.binaryDataMode]) {
|
||||||
return this.managers[this.binaryDataMode].persistBinaryDataForExecutionId(executionId);
|
return this.managers[this.binaryDataMode].persistBinaryDataForExecutionId(executionId);
|
||||||
|
|
Loading…
Reference in a new issue