mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 13:27:31 -08:00
⚡ Small improvements on execution pruning
This commit is contained in:
parent
78dc1e9449
commit
8bfc5a4b65
|
@ -205,8 +205,8 @@ const config = convict({
|
||||||
env: 'EXECUTIONS_DATA_MAX_AGE'
|
env: 'EXECUTIONS_DATA_MAX_AGE'
|
||||||
},
|
},
|
||||||
pruneDataTimeout: {
|
pruneDataTimeout: {
|
||||||
doc: 'Timeout (ms) after execution data has been pruned',
|
doc: 'Timeout (seconds) after execution data has been pruned',
|
||||||
default: 3600000,
|
default: 3600,
|
||||||
env: 'EXECUTIONS_DATA_PRUNE_TIMEOUT'
|
env: 'EXECUTIONS_DATA_PRUNE_TIMEOUT'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -86,22 +86,22 @@ function executeErrorWorkflow(workflowData: IWorkflowBase, fullRunData: IRun, mo
|
||||||
* Throttled to be executed just once in configured timeframe.
|
* Throttled to be executed just once in configured timeframe.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
let throttling: boolean;
|
let throttling = false;
|
||||||
function pruneExecutionData(): void {
|
function pruneExecutionData(): void {
|
||||||
if (!throttling) {
|
if (!throttling) {
|
||||||
throttling = true;
|
throttling = true;
|
||||||
const timeout = config.get('executions.pruneDataTimeout') as number; // in ms
|
const timeout = config.get('executions.pruneDataTimeout') as number; // in seconds
|
||||||
const maxAge = config.get('executions.pruneDataMaxAge') as number; // in h
|
const maxAge = config.get('executions.pruneDataMaxAge') as number; // in h
|
||||||
const date = new Date(); // today
|
const date = new Date(); // today
|
||||||
date.setHours(date.getHours() - maxAge);
|
date.setHours(date.getHours() - maxAge);
|
||||||
|
|
||||||
// throttle just on success to allow for self healing on failure
|
// throttle just on success to allow for self healing on failure
|
||||||
Db.collections.Execution!.delete({ startedAt: LessThanOrEqual(date.toISOString()) })
|
Db.collections.Execution!.delete({ stoppedAt: LessThanOrEqual(date.toISOString()) })
|
||||||
.then(data =>
|
.then(data =>
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
throttling = false;
|
throttling = false;
|
||||||
}, timeout)
|
}, timeout * 1000)
|
||||||
).catch(err => throttling = false)
|
).catch(err => throttling = false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +215,11 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||||
workflowExecuteAfter: [
|
workflowExecuteAfter: [
|
||||||
async function (this: WorkflowHooks, fullRunData: IRun, newStaticData: IDataObject): Promise<void> {
|
async function (this: WorkflowHooks, fullRunData: IRun, newStaticData: IDataObject): Promise<void> {
|
||||||
|
|
||||||
|
// Prune old execution data
|
||||||
|
if (config.get('executions.pruneData')) {
|
||||||
|
pruneExecutionData();
|
||||||
|
}
|
||||||
|
|
||||||
const isManualMode = [this.mode, parentProcessMode].includes('manual');
|
const isManualMode = [this.mode, parentProcessMode].includes('manual');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -284,11 +289,6 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||||
await Db.collections.Execution!.update(this.retryOf, { retrySuccessId: executionResult.id });
|
await Db.collections.Execution!.update(this.retryOf, { retrySuccessId: executionResult.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prune old execution data
|
|
||||||
if (config.get('executions.pruneData')) {
|
|
||||||
pruneExecutionData()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isManualMode) {
|
if (!isManualMode) {
|
||||||
executeErrorWorkflow(this.workflowData, fullRunData, this.mode, executionResult ? executionResult.id as string : undefined, this.retryOf);
|
executeErrorWorkflow(this.workflowData, fullRunData, this.mode, executionResult ? executionResult.id as string : undefined, this.retryOf);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue