mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -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;
|
||||
function pruneExecutionData(this: WorkflowHooks): void {
|
||||
async function pruneExecutionData(this: WorkflowHooks): Promise<void> {
|
||||
if (!throttling) {
|
||||
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
|
||||
const utcDate = DateUtils.mixedDateToUtcDatetimeString(date);
|
||||
|
||||
// throttle just on success to allow for self healing on failure
|
||||
Db.collections.Execution.delete({ stoppedAt: LessThanOrEqual(utcDate) })
|
||||
.then((data) =>
|
||||
try {
|
||||
const executions = await Db.collections.Execution.find({
|
||||
stoppedAt: LessThanOrEqual(utcDate),
|
||||
});
|
||||
await Db.collections.Execution.delete({ stoppedAt: LessThanOrEqual(utcDate) });
|
||||
setTimeout(() => {
|
||||
throttling = false;
|
||||
}, timeout * 1000),
|
||||
)
|
||||
.catch((error) => {
|
||||
}, timeout * 1000);
|
||||
// Mark binary data for deletion for all executions
|
||||
await BinaryDataManager.getInstance().markDataForDeletionByExecutionIds(
|
||||
executions.map(({ id }) => id.toString()),
|
||||
);
|
||||
} catch (error) {
|
||||
ErrorReporter.error(error);
|
||||
|
||||
throttling = false;
|
||||
Logger.error(
|
||||
`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,
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -491,7 +495,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
|||
|
||||
// Prune old execution data
|
||||
if (config.getEnv('executions.pruneData')) {
|
||||
pruneExecutionData.call(this);
|
||||
await pruneExecutionData.call(this);
|
||||
}
|
||||
|
||||
const isManualMode = [this.mode, parentProcessMode].includes('manual');
|
||||
|
|
|
@ -144,6 +144,18 @@ export class BinaryDataManager {
|
|||
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> {
|
||||
if (this.managers[this.binaryDataMode]) {
|
||||
return this.managers[this.binaryDataMode].persistBinaryDataForExecutionId(executionId);
|
||||
|
|
Loading…
Reference in a new issue