🐛 Fix executions pruning and UTC storage (#1959)

*  Add logging for pruning errors

*  Reformat pruning date to UTC string

*  Reformat workflow deletion date to UTC

*  Enforce UTC datetimes for MySQL

*  Enforce UTC datetimes for Postgres

*  Revert "Reformat workflow deletion date to UTC"

This reverts commit ca9628bc6d.
This commit is contained in:
Iván Ovejero 2021-07-23 21:40:53 +02:00 committed by GitHub
parent 2a99a77b43
commit f29950ee81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View file

@ -89,6 +89,7 @@ export async function init(): Promise<IDatabaseCollections> {
migrations: mysqlMigrations, migrations: mysqlMigrations,
migrationsRun: true, migrationsRun: true,
migrationsTableName: `${entityPrefix}migrations`, migrationsTableName: `${entityPrefix}migrations`,
timezone: 'Z', // set UTC as default
}; };
break; break;

View file

@ -46,6 +46,7 @@ import {
import * as config from '../config'; import * as config from '../config';
import { LessThanOrEqual } from 'typeorm'; import { LessThanOrEqual } from 'typeorm';
import { DateUtils } from 'typeorm/util/DateUtils';
const ERROR_TRIGGER_TYPE = config.get('nodes.errorTriggerType') as string; const ERROR_TRIGGER_TYPE = config.get('nodes.errorTriggerType') as string;
@ -102,7 +103,7 @@ function executeErrorWorkflow(workflowData: IWorkflowBase, fullRunData: IRun, mo
* *
*/ */
let throttling = false; let throttling = false;
function pruneExecutionData(): void { function pruneExecutionData(this: WorkflowHooks): void {
if (!throttling) { if (!throttling) {
Logger.verbose('Pruning execution data from database'); Logger.verbose('Pruning execution data from database');
@ -112,13 +113,20 @@ function pruneExecutionData(): void {
const date = new Date(); // today const date = new Date(); // today
date.setHours(date.getHours() - maxAge); date.setHours(date.getHours() - maxAge);
// date reformatting needed - see https://github.com/typeorm/typeorm/issues/2286
const utcDate = DateUtils.mixedDateToUtcDatetimeString(date);
// 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({ stoppedAt: LessThanOrEqual(date.toISOString()) }) Db.collections.Execution!.delete({ stoppedAt: LessThanOrEqual(utcDate) })
.then(data => .then(data =>
setTimeout(() => { setTimeout(() => {
throttling = false; throttling = false;
}, timeout * 1000) }, timeout * 1000)
).catch(err => throttling = false); ).catch(error => {
throttling = false;
Logger.error(`Failed pruning execution data from database for execution ID ${this.executionId} (hookFunctionsSave)`, { ...error, executionId: this.executionId, sessionId: this.sessionId, workflowId: this.workflowData.id });
});
} }
} }
@ -322,7 +330,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
// Prune old execution data // Prune old execution data
if (config.get('executions.pruneData')) { if (config.get('executions.pruneData')) {
pruneExecutionData(); pruneExecutionData.call(this);
} }
const isManualMode = [this.mode, parentProcessMode].includes('manual'); const isManualMode = [this.mode, parentProcessMode].includes('manual');

View file

@ -18,7 +18,7 @@ export function resolveDataType(dataType: string) {
json: 'simple-json', json: 'simple-json',
}, },
postgresdb: { postgresdb: {
datetime: 'timestamp', datetime: 'timestamptz',
}, },
mysqldb: {}, mysqldb: {},
mariadb: {}, mariadb: {},