refactor(core): Port workflow history config (#14689)

This commit is contained in:
Iván Ovejero
2025-04-17 13:09:40 +02:00
committed by GitHub
parent 8325ca1a45
commit 3cdc8b41be
8 changed files with 43 additions and 34 deletions
@@ -1,9 +1,12 @@
import config from '@/config';
import { GlobalConfig } from '@n8n/config';
import { Container } from '@n8n/di';
import { License } from '@/license';
import { getWorkflowHistoryPruneTime } from '@/workflows/workflow-history.ee/workflow-history-helper.ee';
import { mockInstance } from '@test/mocking';
let licensePruneTime = -1;
const globalConfig = Container.get(GlobalConfig);
beforeAll(async () => {
mockInstance(License, {
@@ -15,39 +18,39 @@ beforeAll(async () => {
beforeEach(() => {
licensePruneTime = -1;
config.set('workflowHistory.pruneTime', -1);
globalConfig.workflowHistory.pruneTime = -1;
});
describe('getWorkflowHistoryPruneTime', () => {
test('should return -1 (infinite) if config and license are -1', () => {
licensePruneTime = -1;
config.set('workflowHistory.pruneTime', -1);
globalConfig.workflowHistory.pruneTime = -1;
expect(getWorkflowHistoryPruneTime()).toBe(-1);
});
test('should return config time if license is infinite and config is not', () => {
licensePruneTime = -1;
config.set('workflowHistory.pruneTime', 24);
globalConfig.workflowHistory.pruneTime = 24;
expect(getWorkflowHistoryPruneTime()).toBe(24);
});
test('should return license time if config is infinite and license is not', () => {
licensePruneTime = 25;
config.set('workflowHistory.pruneTime', -1);
globalConfig.workflowHistory.pruneTime = -1;
expect(getWorkflowHistoryPruneTime()).toBe(25);
});
test('should return lowest of config and license time if both are not -1', () => {
licensePruneTime = 26;
config.set('workflowHistory.pruneTime', 100);
globalConfig.workflowHistory.pruneTime = 100;
expect(getWorkflowHistoryPruneTime()).toBe(26);
licensePruneTime = 100;
config.set('workflowHistory.pruneTime', 27);
globalConfig.workflowHistory.pruneTime = 27;
expect(getWorkflowHistoryPruneTime()).toBe(27);
});
@@ -1,6 +1,6 @@
import { GlobalConfig } from '@n8n/config';
import { Container } from '@n8n/di';
import config from '@/config';
import { License } from '@/license';
export function isWorkflowHistoryLicensed() {
@@ -9,7 +9,7 @@ export function isWorkflowHistoryLicensed() {
}
export function isWorkflowHistoryEnabled() {
return isWorkflowHistoryLicensed() && config.getEnv('workflowHistory.enabled');
return isWorkflowHistoryLicensed() && Container.get(GlobalConfig).workflowHistory.enabled;
}
export function getWorkflowHistoryLicensePruneTime() {
@@ -19,7 +19,7 @@ export function getWorkflowHistoryLicensePruneTime() {
// Time in hours
export function getWorkflowHistoryPruneTime(): number {
const licenseTime = Container.get(License).getWorkflowHistoryPruneLimit();
const configTime = config.getEnv('workflowHistory.pruneTime');
const configTime = Container.get(GlobalConfig).workflowHistory.pruneTime;
// License is infinite and config time is infinite
if (licenseTime === -1) {